PHP 5 SSH2 函数

发布于 2024-11-20 00:09:10 字数 917 浏览 1 评论 0原文

我已经在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦回梦里 2024-11-27 00:09:10

您似乎已指定保存文件的位置目录,而不是文件名。

It looks like you've specified a directory for the location to save your file to, rather than a filename.

我很坚强 2024-11-27 00:09:10

请检查“/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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文