【问题标题】:how to solve multi upload with sftp in php codeigniter如何在 php codeigniter 中使用 sftp 解决多上传问题
【发布时间】: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


    【解决方案1】:

    如果您在本地主机上工作,则必须增加页面加载时间。 一旦托管,无需增加加载时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-20
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多