PHP 5 SSH2 函数
我已经在我的 CentOS WHM/CPanel 服务器中安装并启用了 SSH2,这里来自 PHP INFO:
ssh2 已启用 SSH2 支持 扩展版本0.11.2 libssh2 版本 0.18 横幅 SSH-2.0-libssh2_0.18 远程转发已启用 启用基于主机的身份验证 启用轮询支持 启用公钥子系统
注册 PHP 流 https, ftps, compress.zlib, php, file, glob, data, http, ftp, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp
但是,任何时候我尝试要使用 SSH2 PHP 函数接收文件,我得到:
警告:ssh2_scp_recv(/home/XXXX) [function.ssh2-scp-recv]:失败 打开流:是第 16 行 /pathtoFile 中的目录
这是代码:
if($connection = ssh2_connect('www.server.com', 22)){
echo("connected");
}else{
echo("NOT connected");
}
if(ssh2_auth_password($connection, 'username', 'mypassword')){
echo("password ok");
}else{
echo("password WRONG");
}
if(ssh2_scp_recv($connection, '/home/pathtoDLfile', '/home/pathtoLocationDestination')){
echo("received");
}else{
echo("NOT received");
}
echo("end");
I have installed and enabled SSH2 in my CentOS WHM/CPanel server, here is from PHP INFO:
ssh2
SSH2 support enabled
extension version 0.11.2
libssh2 version 0.18
banner SSH-2.0-libssh2_0.18
remote forwarding enabled
hostbased auth enabled
polling support enabled
publickey subsystem enabled
Registered PHP Streams https, ftps, compress.zlib, php, file, glob, data, http, ftp, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp
However, anytime I try to use the SSH2 PHP functions to receive a file, I get this:
Warning: ssh2_scp_recv(/home/XXXX) [function.ssh2-scp-recv]: failed to
open stream: Is a directory in /pathtoFile on line 16
Here's the code:
if($connection = ssh2_connect('www.server.com', 22)){
echo("connected");
}else{
echo("NOT connected");
}
if(ssh2_auth_password($connection, 'username', 'mypassword')){
echo("password ok");
}else{
echo("password WRONG");
}
if(ssh2_scp_recv($connection, '/home/pathtoDLfile', '/home/pathtoLocationDestination')){
echo("received");
}else{
echo("NOT received");
}
echo("end");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎已指定保存文件的位置目录,而不是文件名。
It looks like you've specified a directory for the location to save your file to, rather than a filename.
请检查“/home/pathtoDLfile”和“/home/pathtoLocationDestination”以确保它们是文件名,而不是目录。
特别注意,目标位置('/home/pathtoLocationDestination')需要是文件名,而不仅仅是目录路径。如果您当前仅指定了目录名称,则可以将所需的文件名附加到路径中。
Please check '/home/pathtoDLfile' and '/home/pathtoLocationDestination' to ensure that they are file names, not directory.
Note especially that the destination location ('/home/pathtoLocationDestination') needs to be a file name, not just a directory path. You can append your desired filename to the path if you have currently specified only the directory name.