gpt4 book ai didi

php - SCP 与 PHP - 不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 05:06:20 26 4
gpt4 key购买 nike

尝试使用 PHP 将文件上传到不同的服务器。它与 ssh_connect() 成功连接,但是当我包含 ssh2_scp_send 时,显示的页面是空白的(好像存在语法错误),并且它肯定没有上传文件。知道为什么会这样吗?我更喜欢使用 PHP,但如果它不起作用,我想我可以使用私钥文件对 CLI scp 进行系统调用,但我不想这样做。欢迎提出替代建议。

Info: debian w/apache

Installed: libssh2-1-dev libssh2-php php-pear php5-dev; pecl install -f ssh2

$ssh = ssh2_connect('localhost', 22);
ssh2_auth_password($ssh, 'user', 'password');
ssh2_scp_send($ssh, 'original', 'destination'); # does not work
ssh2_exec($ssh, 'exit'); #does not help

有什么想法吗?

最佳答案

就个人而言,我建议使用 phpseclib, a pure PHP SFTP implementation :

<?php
include('Net/SFTP.php');

$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}

echo $sftp->pwd() . "\r\n";
$sftp->put('filename.ext', 'hello, world!');
print_r($sftp->nlist());
?>

libssh2 的主要问题是它不容易安装。原作者已放弃它。 php.net 上的源代码需要修改才能编译,尽管您现在可以在 Ubuntu 上使用 apt-get 安装它,但当它需要的不仅仅是两条新行才能工作时会发生什么?如果您尝试运行的 Linux 机器不是 Ubuntu 怎么办?

如果您需要创建一个新服务器来托管您的网站,您不希望在一堆深奥的依赖项上花费数小时。

关于php - SCP 与 PHP - 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7455699/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com