试图在PHP中进行SFTP,导致500个错误



我已经尝试了几种连接到SFTP服务器的方法,在所有情况下,我在连接或尝试上传文件时都会收到500个错误。

我尝试连接到两个不同的服务器,每次都会获得相同的结果。i 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:inetpubwwwrootTimeSavrRefreshcommoninitialize.php on line 111
[25-Sep-2017 09:53:15 America/Edmonton] PHP Notice:  Undefined variable: content in C:inetpubwwwrootTimeSavrRefreshcommoncommon.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:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:phppear') in C:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:phppear') in C:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:phppear') in C:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:phppear') in C:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.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:inetpubwwwrootTimeSavrRefreshcommonPHP SFTPNetSSH2.php on line 1243

结果,phpseclib代码无法找到以下文件:

Math/BigInteger.php
Crypt/Random.php
Crypt/Hash.php
Crypt/Base.php

...因为脚本依赖于php包含路径,默认情况下为c: php pear。

因此,我通过在脚本的顶部添加以下两行解决了它。

$currentdirectory = getcwd();
set_include_path(get_include_path().";".$currentdirectory.'/common/PHP SFTP');

最新更新