【发布时间】:2015-03-08 16:04:16
【问题描述】:
我目前正在努力使用 PHP 的 SSH2 内置库(运行版本 5.5)。如标题所述,我正在尝试将文件上传到 SFTP 服务器,但是我不断收到“流操作失败”错误消息。
在尝试调试代码本身后,连接工作正常,sftp 资源被正确分配了一个 ID,但是当调用 fopen 将文件直接写入远程服务器时,它会失败。
// open Live environment if we are not in dev
$connection = ssh2_connect($this->_settings['source_host'], 22);
$authSuccess = ssh2_auth_password($connection, $this- >_settings['source_user'], $this->_settings['source_password']);
$sftp = ssh2_sftp($connection);
最后是 fopen() 调用:
if($operation == 'export') {
$handle = fopen("ssh2.sftp://".$sftp."/remotecopy/IN/".$filename, $mode);
}
我在自己的代码中添加了调试消息,以验证 _settings 数组中的数据是否也被正确使用,但我无法解释流错误。
Message: fopen(): Unable to open ssh2.sftp://Resource id #173/PATH GOES HERE/filename.xxx on remote host
Message: fopen(ssh2.sftp://Resource id #173/PATH GOES HERE/filename.xxx): failed to open stream: operation failed
请注意,该文件在远程主机上不存在,但据我所知,PHP fopen() 中的“w”模式应该在文件不存在时创建该文件。
我不能使用其他 PHP 库,因为我们的整个项目都使用内置的 ssh2 库,负责人告诉我不要使用它,因为它在其他任何地方都可以正常工作。
【问题讨论】:
-
fopen是否可能在您的服务器上被禁用? -
也许,我不知道。验证后好像开启了。