dimanche 13 octobre 2019

Move file from SFTP to projects storage folder

I am having a few issues moving a file from SFTP to a my projects storage folder. So I am connecting to SFTP like so

 try {
    $filesystem = new Filesystem(new SftpAdapter([
        'host' => $sftp->sftp_host,
        'port' => $sftp->sftp_port,
        'username' => $sftp->sftp_user,
        'password' => $sftp->sftp_password,
        'root' => $sftp->sftp_path,
        'timeout' => 10,
    ]));
} catch (Exception $exception){
    throw new Exception("Could not connect to SFTP.");
}

I then check if the file I am after exists

if ($filesystem->has($sftp->csv_filename)) {

}

If it does, I am then trying to copy the file to a new location

if ($filesystem->has($sftp->csv_filename)) {
    $file = $filesystem->copy($sftp->csv_filename, $this->newFilePath($report_type));
    dd($file);
} else {
    throw new Exception("File not found.");
}

protected function newFilePath($type)
{
    $dateFolder = date("Y-m-d");
    $filePath = $this->getUserDir() . "/{$type}/{$dateFolder}/";
    $finalPath = storage_path("app/public/" . $filePath);

   return $finalPath;
}

protected function getUserDir()
{
    return 'user_' . Auth::user()->id;
}

When I run this, the dd seems to return true. However, no file is in the location I expect it to be in.

Am I missing something here?

Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2B4MiVw
via IFTTT

Aucun commentaire:

Enregistrer un commentaire