我尝试了几种不同的连接SFTP服务器的方法,在所有情况下,当我连接或尝试上传文件时,都会收到500错误。
我尝试过连接两台不同的服务器,每次都获得相同的结果。我 am 但是能够使用GUI界面客户端连接到两台服务器,没问题。
使用SSH2_connect:
//<!--************************************************************************-->
//<!--*** Connect using ssh2
//<!--************************************************************************-->
$conn = ssh2_connect($ftp_host, 22);
ssh2_auth_password($conn, $ftp_username, $ftp_password);
//<!--************************************************************************-->
//<!--*** Send the file
//<!--************************************************************************-->
ssh2_scp_send($conn, $localfile, $remote_file);
连接通话会导致500错误。
我也尝试使用PHPSecLib,正如StackExchange上的很多人所推荐的那样,但我遇到了同样的问题。
include("common/PHP SFTP/Net/SFTP.php");
//<!--************************************************************************-->
//<!--*** Connect using sftp
//<!--************************************************************************-->
$sftp = new Net_SFTP($ftp_host);
//<!--************************************************************************-->
//<!--*** Log into ftp server
//<!--************************************************************************-->
if ($sftp->login($ftp_username, $ftp_password)) {
//<!--************************************************************************-->
//<!--*** Send local file via ftp
//<!--************************************************************************-->
if(!$sftp->put($remote_file, $localfile)){
errorLog(1,"DEBUG","eft transfer","Fail");
}
}else{
errorLog(1,"DEBUG","sftp connection","Fail");
}
//<!--************************************************************************-->
//<!--*** Close the connection
//<!--************************************************************************-->
ftp_close($ftp_connection);
在这种情况下,创建一个新的Net_SFTP对象不会导致问题,因此它不是包含的PHPSecLib文件的路径问题,但是一旦我尝试登录到ftp服务器,它就会因为500错误而崩溃。
使用phpinfo()我已经确认我在服务器上启用了OpenSSL。 SFTP协议也已启用。 SSH2 DLL也已安装并启用。
我不知道还有什么要找。
这些是我的日志文件中的错误
[25-Sep-2017 11:53:15 America/New_York] PHP Notice: Undefined index: pagedate in C:\inetpub\wwwroot\TimeSavr\Refresh\common\initialize.php on line 111
[25-Sep-2017 09:53:15 America/Edmonton] PHP Notice: Undefined variable: content in C:\inetpub\wwwroot\TimeSavr\Refresh\common\common.php on line 8
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(Math/BigInteger.php): failed to open stream: No such file or directory in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 891
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(): Failed opening 'Math/BigInteger.php' for inclusion (include_path='.;C:\php\pear') in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 891
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(Crypt/Random.php): failed to open stream: No such file or directory in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 895
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(): Failed opening 'Crypt/Random.php' for inclusion (include_path='.;C:\php\pear') in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 895
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(Crypt/Hash.php): failed to open stream: No such file or directory in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 899
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(): Failed opening 'Crypt/Hash.php' for inclusion (include_path='.;C:\php\pear') in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 899
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(Crypt/Base.php): failed to open stream: No such file or directory in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 904
[25-Sep-2017 09:53:15 America/Edmonton] PHP Warning: include_once(): Failed opening 'Crypt/Base.php' for inclusion (include_path='.;C:\php\pear') in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 904
[25-Sep-2017 09:53:16 America/Edmonton] PHP Fatal error: Call to undefined function phpseclib_resolve_include_path() in C:\inetpub\wwwroot\TimeSavr\Refresh\common\PHP SFTP\Net\SSH2.php on line 1243
答案 0 :(得分:1)
原来phpseclib代码无法找到以下文件:
Math/BigInteger.php
Crypt/Random.php
Crypt/Hash.php
Crypt/Base.php
...因为脚本依赖于php include路径,默认情况下是c:\ php \ pear。
所以我通过在脚本的顶部添加以下两行来解决它。
$currentdirectory = getcwd();
set_include_path(get_include_path().";".$currentdirectory.'/common/PHP SFTP');