在Ubuntu机器下,我想创建一个允许我通过SFTP发送文件的脚本。为此,我使用以下代码:
$connection = ssh2_connect('XXX', 22);
if (ssh2_auth_password($connection, 'USER', 'PASS')) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}
为第一个结果:
Warning: ssh2_auth_password(): Authentication failed for ...
我想通过阅读大量扩展ssh2.so缺失的教程。所以我安装了它仍然没有结果。
答案 0 :(得分:1)
我会建议phpseclib, a pure PHP SFTP implementation。
而不是基于ssh2的函数使用phpseclib可以:
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('www.domain.com');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
echo $sftp->pwd() . "\r\n";
$sftp->put('filename.ext', file_get_contents('localfile.data'););
print_r($sftp->nlist());
?>
答案 1 :(得分:-2)
您可以使用流机制:将目标文件作为
$dest = "ftps://user:pwd@server.com/destinationfile.txt"
然后使用标准的php copy
函数:
copy($from, $dest)