doujiao6507 2017-09-24 22:54
浏览 111
已采纳

尝试在PHP中使用SFTP导致500错误

I've tried several different methods of connecting to an SFTP server and in all cases I get a 500 error either when I connect or when I try to upload a file.

I've tried connecting to two different servers, getting the same results each time. I am however able to connect to both servers using a GUI interface client, no problem.

Using 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);

The connect call causes a 500 error.

I also tried using PHPSecLib, as recommended by so many people on StackExchange, but I run into the same problem.

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);

In this case creating a new Net_SFTP object causes no problems so it's not a pathing issue to the included PHPSecLib file, but as soon as I try to login to the ftp server it falls over with a 500 error.

Using phpinfo() I've confirmed that I have OpenSSL enabled on the server. SFTP protocol is also enabled. SSH2 DLL is also installed and enabled.

I don't know what else to look for.

These are the errors in my log file

[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
  • 写回答

1条回答 默认 最新

  • dqsxsmi3704 2017-09-25 16:35
    关注

    Turns out the phpseclib code was unable to find the following files:

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

    ...because the script relies on the php include path which by default is c:\php\pear.

    So I solved it by adding the following two lines to the top of my script.

    $currentdirectory = getcwd();
    set_include_path(get_include_path().";".$currentdirectory.'/common/PHP SFTP');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 VB.NET如何绘制倾斜的椭圆