我使用phpseclib类通过SFTP上传CSV文件。 我做了以下事情:
include('vendor/autoload.php');
use phpseclib\Crypt\RSA;
use phpseclib\Net\SFTP;
$sftp = new SFTP($sftpServerHost);
$Key = new RSA();
$Key->setPassword($sftpKeyPassword);
$Key->loadKey(file_get_contents($sftpKey));
if (!$sftp->login($sftpUserName, $Key)) {
throw new Exception('Login failed');
}else{
$sftp->chdir('upload');
$sftp->put($filename, $output);
}
$ output - 是CSV文件的内容。 如果内容小于~40行,则文件上传没有问题,但如果内容> 40行,则脚本挂起一段时间然后输出几行错误:
PHP Notice: Uninitialized string offset: 0 in /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 3167
PHP Notice: Connection closed prematurely in /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 3025
PHP Notice: Connection closed by server in /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 3373
PHP Notice: Expected SSH_FXP_STATUS in /vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php on line 2027
PHP Notice: Connection closed prematurely in /vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php on line 3599
结果文件未上传。 有任何建议如何修复它?