[英]SSH2 what am I doing wrong?
I'm having trouble copying a file from my laravel project to another server. 我无法将文件从laravel项目复制到另一台服务器。 This is what I'm doing.
这就是我在做什么。
$connection = ssh2_connect($this->ftpHostname, $this->ftpPort);
if (!$connection) {
throw new \Exception("Couldn't connect to {$this->ftpHostname}:{$this->ftpPort}");
}
$loginResult = ssh2_auth_password($connection, 'usrname', 'pswrd');
if (!$loginResult) {
throw new \Exception("Username or Password not accepted for {$this->ftpHostname}:{$this->ftpPort}");
}
$sftp = ssh2_sftp($connection);
$fullFilePath = storage_path() .'/'.$this->argument('local-file');
$remoteFilePath = "ssh2.sftp://{$sftp}/{$this->argument('remote-folder')}/SomeFolder/{$this->argument('remote-filename')}.txt";
$copyResult = copy($fullFilePath, $remoteFilePath);
But it's giving me this error 但这给了我这个错误
[ErrorException]
copy(): Unable to open ssh2.sftp://Resource id #621/My Folders/Upload only/sample.txt on remote host
I'm really new in ssh how do I solve this? 我真的是ssh的新手,如何解决这个问题?
Cast $sftp to an int before using it in the ssh2.sftp:// fopen wrapper. 在ssh2.sftp:// fopen包装器中使用$ sftp之前,将其转换为int。
$remoteFilePath = "ssh2.sftp://" . (int)$sftp . "/{$this->argument('remote-folder')}/SomeFolder/{$this->argument('remote-filename')}.txt";
The example code above fails unless you cast the $stftp to (int) or use intval()
除非将$ stftp强制转换为(int)或使用intval(),否则上述示例代码将失败。
$stream = fopen("ssh2.sftp://$sftp/path/to/file", 'r');
$ stream = fopen(“ ssh2.sftp:// $ sftp / path / to / file”,'r'); // Fails
//失败
$stream = fopen("ssh2.sftp://" . (int)$sftp . "/path/to/file", 'r');
$ stream = fopen(“ ssh2.sftp://”。(int)$ sftp。“ / path / to / file”,'r'); // joy
//欢乐
Since copy() will be using the fopen wrappers to interpret your ssh2.sftp:// uri, that should help. 由于copy()将使用fopen包装器来解释ssh2.sftp:// uri,因此应该会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.