我在使用PHP将SFTP上传文件到远程服务器时遇到了问题。当我使用卷曲,我得到这里所描述的错误:如何从SFTP上传PHP的文件
SFTP from PHP - undefined constant CURLOPT_PROTOCOLS and CURLPROTO_SFTP?
我也试过phpseclib中建议:
但是当我尝试phpseclib,我得到这些错误:
Warning: require_once(Math/BigInteger.php) [function.require-once]: failed to open stream: No such file or directory in /home/john/public_html/test/Net/SSH2.php on line 53
Fatal error: require_once() [function.require]: Failed opening required 'Math/BigInteger.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/john/public_html/test/Net/SSH2.php on line 53
然后我尝试在php中使用系统命令就像这样,但没有发生任何事情:
<?php
echo system('sftp [email protected]');
echo system('password');
echo system('put file.csv');
?>
我也试过
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>
,但我的PHP服务器说没有定义ss2_connect。
我试着做从终端
scp file.csv [email protected]
password
以下但服务器不允许scp命令。我没有shell访问权限来创建ssh密钥。
我现在所能做的就是从终端sftp并手动上传。但我真的想自动化,所以PHP网站可以做到这一切。
关于如何从PHP上传SFTP的教程并不多。是因为这是一件坏事吗?如果是这样,我该怎么做?我想要上传到的服务器只允许sftp连接。
我正在处理的服务器说ssh2_connect()没有定义。另外,我连接的远程主机不允许我scp file.csv [email protected] – John
这可能不是默认情况下可用的。您需要使用libssh2的PECL ssh2扩展。 –