我无法从我的laravel项目复制文件到另一台服务器。 这是我正在做的。
$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);
但它给了我这个错误
[ErrorException] copy(): Unable to open ssh2.sftp://Resource id #621/My Folders/Upload only/sample.txt on remote host
我真的很新的SSH如何解决这个问题?
在使用ssh2.sftp:// fopen包装器之前,将$ sftp转换为一个int值。
$remoteFilePath = "ssh2.sftp://" . (int)$sftp . "/{$this->argument('remote-folder')}/SomeFolder/{$this->argument('remote-filename')}.txt";
从ssh2_sftp
上面的示例代码失败,除非您将$ stftp强制转换为(int)或使用intval()
$ stream = fopen(“ssh2.sftp:// $ sftp / path / to / file”,“r”); //失败
$ stream = fopen(“ssh2.sftp://”。(int)$ sftp。“/ path / to / file”,“r”); //快乐
由于copy()将使用fopen包装来解释你的ssh2.sftp:// uri,这应该有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。