[英]Unable to send or receive file using ssh2_scp_recv and ssh2_scp_send
Not sure what's wrong but I am unable to send or receive file using SSH. 不知道出了什么问题,但是我无法使用SSH发送或接收文件。
I am using the following code 我正在使用以下代码
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");
}
Neither this nor file_get_contents
function is working. 此功能和file_get_contents
函数均file_get_contents
。 The strange thing is that I am able to get file stats by calling 奇怪的是,我能够通过调用获取文件统计信息
$sftp = ssh2_sftp($connection);
$statinfo = ssh2_sftp_stat($sftp, $remoteFile);
But unable to read file data. 但是无法读取文件数据。
Is there some special permission I have to set on either server? 我必须在任一服务器上设置一些特殊权限吗?
SCP and SFTP are different things. SCP和SFTP是不同的东西。 Probably, SCP is disabled on your server. SCP可能已在您的服务器上禁用。
I would use phpseclib, a pure PHP SFTP implementation . 我将使用phpseclib,这是纯PHP SFTP实现 。 Easier to use and easier to diagnose problems with it due to its logging capabilities. 由于具有日志记录功能,因此更易于使用且更易于诊断问题。 ie. 即。
<?php
include('Net/SFTP.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
$ssh = new Net_SFTP('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
$ssh->put('filename.ext', 'zzzzzzzzzzzzzzz');
echo $ssh->getLog();
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.