-1

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

我尝试连接到两个不同的服务器,每次都得到相同的结果。但是,我可以使用 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
4

1 回答 1

1

原来 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');
于 2017-09-25T16:35:18.397 回答