【发布时间】:2019-02-23 12:44:41
【问题描述】:
我在使用 PHP Codeigniter 将文件 SFTP 上传到远程服务器时遇到问题。 当我上传多个文件时。所以这里是我的代码:
for($row = 0; $row < $total; $row++)
{
$origin = $directory.$file[$row];
$destination = $des.$file[$row];
$send= $this->upload($config,$origin,$destination);
$filename = $file[$row];
print_r($filename."\n");
} $this->sftp->close();
所以如果我有 1000 个文件要上传,并且从 1 到 50 成功上传。但是当文件 51 上传失败并收到错误消息时
ftp 无法上传
什么原因可以显示上面的错误,如何创建重新连接和重新上传下一个文件的句柄。所以这个函数:
public function upload($config,$origin,$destination)
{
$connect = $this->sftp->connect($config);
$upload = $this->sftp->upload($origin, $destination, 'ascii', '0775');
//create handling upload
return $upload;
}
以及从库 sftp 上传示例函数:
$file_to_send = @file_get_contents($locpath);
$sftp = intVal($this->sftp);
$stream = fopen("ssh2.sftp://{$sftp}{$rempath}", 'w');
if (@fwrite($stream, $file_to_send) === FALSE)
{
if ($this->debug == TRUE)
{
$this->_error('ftp_unable_to_upload');
}
return FALSE;
}
return TRUE
来自library sftp的源sftp库
所以当上传获取消息ftp无法上传时如何处理重新连接和重新上传文件。谢谢
【问题讨论】:
标签: php codeigniter ftp sftp