forked from rodrigopedra/laravel-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecureShellCommand.php
48 lines (44 loc) · 1.22 KB
/
SecureShellCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App;
class SecureShellCommand
{
/**
* Build an SSH command for the given script.
*
* @param string $ipAddress
* @param string $keyPath
* @param int $port
* @param string $user
* @param string $script
* @return string
*/
public static function forScript($ipAddress, $port, $keyPath, $user, $script)
{
$token = str_random(40);
return implode(' ', [
'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no',
'-i '.$keyPath,
'-p '.$port,
$user.'@'.$ipAddress,
$script,
]);
}
/**
* Build an SSH command for a file upload.
*
* @param string $ipAddress
* @param string $keyPath
* @param int $port
* @param string $user
* @param string $from
* @param string $to
* @return string
*/
public static function forUpload($ipAddress, $port, $keyPath, $user, $from, $to)
{
return sprintf(
'scp -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PasswordAuthentication=no -P %s %s %s:%s',
$keyPath, $port, $from, $user.'@'.$ipAddress, $to
);
}
}