【发布时间】:2014-04-09 19:57:55
【问题描述】:
我正在尝试: - 连接到服务器 - 列出所有文件 - 读取文件并回显内容。
连接正常:
$conn_id = ssh2_connect('xxx.com', 22);
$login_result = ssh2_auth_password($conn_id, 'xxxxxx', 'xxxxxxxxx');
$sftp = ssh2_sftp($conn_id);
$dir = "ssh2.sftp://$sftp/home";
$ftp_contents = scanFilesystem($dir);
然后我遍历目录并获取所有文件名,就像一个魅力一样工作:
foreach($ftp_contents as $key => $currentFilename){
echo($currentFilename);
}
然后我尝试获取文件的内容....但它不起作用。
$stream = fopen("ssh2.sftp://$sftp/home/".$currentFilename, 'r');
echo($stream);
有输出错误:
警告:fopen(ssh2.sftp://Resource id #4/home/myfile.xml) [function.fopen]: failed to open stream: operation failed in /home/xxxxxx/public_html/xxx.php on line 38
第 38 行是 foreach 的结尾。
我尝试:
fopen("ssh2.sftp://$sftp/home/".$currentFilename, 'r');
fopen("ssh2.sftp://$sftp/".$currentFilename, 'r');
fopen("/home/".$currentFilename, 'r');
fopen("home/".$currentFilename, 'r');
没有任何效果,总是出现相同类型的错误,有人可以帮帮我吗? 谢谢。
更新:我尝试使用:$stream = file_get_contents("ssh2.sftp://$sftp/home/$data"); 也不起作用...
还是报错:
警告:file_get_contents() [function.file-get-contents]: Unable to open ssh2.sftp://Resource id #3/xxx.xml on remote host in /home/xxxxxx/public_html/xxxx.php on第 40 行
我不知道...有人可以帮我吗?
【问题讨论】:
-
在多次尝试失败后,我放弃了 php 内置的 ssh2 功能,并开始使用:phpseclib.sourceforge.net
-
谢谢,但这不是重点,我绝对需要那样做,所以谢谢,但不谢谢! ;)
-
可能是权限问题..
-
7,7,7 已设置在文件夹中...所以这似乎不是问题...有人知道吗?
-
我仍然有错误,但现在它的 Ressource id/#3 而不是 #4 ...我不知道。
标签: php ssh fopen file-get-contents ssh2-sftp