如何从PHP上传SFTP文件
作者:互联网
我在使用PHP来SFTP上传文件到远程服务器时遇到了麻烦.当我使用cURL时,我收到此处描述的错误:
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 user@ftp.domain.com');
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 user@ftp.remote.com
password
但是服务器不允许使用scp命令.我没有shell访问权限来创建ssh密钥.
我现在能做的就是从终端sftp并手动上传.但我真的想自动化这个,所以PHP网站可以做到这一切.
关于如何从PHP上传SFTP的教程并不多.是因为这是一件坏事吗?如果是这样,我该怎么办?我要上传的服务器只允许sftp连接.
解决方法:
http://phpseclib.sourceforge.net/documentation/intro.html#intro_usage_correct
因此,phpseclib的根目录需要在您的include_path中.从该页面:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SFTP.php');
?>
你应该真正熟悉这种包含技术 – 它是PEAR库和Zend库的标准.
标签:php,sftp,phpseclib 来源: https://codeday.me/bug/20190527/1159935.html