sftp下载文件

$conf = $this->getSftpConfig();

$conn = ssh2_connect($conf['host'],$conf['port']);

if (!ssh2_auth_password($conn, $conf['user'], $conf['password'])) {
    \Log::info('ftps 连接失败');
}

if (config('licai.env') == 'production') {
    $this->remotFile = '/file/t0/tradedetail/'. $date .'/tradedetail_'.$conf['channelId'] . '_' . $date . '.txt';
} else {
    $this->remotFile = '/file/t0/tradedetail/'. $date .'/tradedetail_'.$conf['channelId'] . '_' . $date . '.txt';
}

$this->dateStr = $date;
$this->basePath = base_path().'/storage/data';

// 创建文件夹
if (!is_dir($this->basePath)) {

    $dir = mkdir($this->basePath, 0777, true);
    if (!$dir) {
        return false;
    }

}
// 如果文件已存在就覆盖
$this->localFile =  $this->basePath . '/' .'ztb' . $date . '.txt';

// 如果文件存在就进行覆盖
if (is_file($this->localFile)) {
    unlink($this->localFile);
}

$sftp = ssh2_sftp($conn);

$resource = "ssh2.sftp://{$sftp}" .  $this->remotFile;

//远程文件 拷贝到本地
 copy($resource, $this->localFile);

你可能感兴趣的:(杂项)