不确定出了什么问题,但我无法使用 SSH 发送或接收文件。
我正在使用以下代码
define('SSH_HOST', 'HOST');
define('SSH_USER', 'USER');
define('SSH_PASS', 'PASSWORD');
$connection = ssh2_connect(SSH_HOST, 22);
ssh2_auth_password($connection, SSH_USER, SSH_PASS);
$remoteFile = '/remote/absolute/path/file.ext';
$localFile = '/local/absolute/path/file.ext';
if(ssh2_scp_recv($connection, $remoteFile, $localFile)){
echo("received");
}else{
echo("NOT received");
}
这个函数和 file_get_contents
函数都不起作用。
奇怪的是,我可以通过调用
$sftp = ssh2_sftp($connection);
$statinfo = ssh2_sftp_stat($sftp, $remoteFile);
但无法读取文件数据。
我必须在任一服务器上设置一些特殊权限吗?
最佳答案
SCP 和 SFTP 是不同的东西。可能您的服务器上禁用了 SCP。
关于php - 无法使用 ssh2_scp_recv 和 ssh2_scp_send 发送或接收文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7852974/