我正在尝试通过SFTP编写内容,并且发生了一些奇怪的事情。
这是一个通用的示例脚本:
<?php
$resConnection = ssh2_connect("<url>");
if (ssh2_auth_password($resConnection, "<name>", '<password>')){
//Initialize SFTP subsystem
echo "connected";
$resSFTP = ssh2_sftp($resConnection);
$resFile = fopen("ssh2.sftp://{$resSFTP}/"."test", 'w');
fwrite($resFile, "Testing");
fclose($resFile);
} else {
echo "Unable to authenticate on server";
}
它的输出是这样的:
root@0fb6a2a1af08:/var/www# php test.php
connected
Warning: fopen(ssh2.sftp://Resource id #5/test): failed to open stream: operation failed in /var/www/test.php on line 8
Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/test.php on line 9
Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/test.php on line 10
所以基本上它可以连接,但不能写任何东西。具有相同凭据的相同代码可以在另一台计算机上正常工作。
SFTP端的某些特定配置是否可能阻止我进行写操作?
答案 0 :(得分:0)
好吧,它与以下错误有关:
目前的解决方案是按照文档中所说的const callback = (foo.addListener as jest.Mock).mock.calls[0][0];
在资源字符串周围使用:https://www.php.net/manual/ru/function.ssh2-sftp.php
intval