Crazylife's avatar

How to cut all the file from a directory from sftp server to local server using file system?

I have a server used to store exchange file.

/uploads/a.txt
/uploads/b.txt
....so on

I am using this to get all of the file inside /uploads/ dir.

  $list = Storage::disk('sftp')->allfiles();

After that, i use foreach to loop every file based on directory to my local.

 Storage::disk('save')->put($old,$new);

Right now i only able to save the file to local without cleaning the /uploads/ dir, and not sure is this practical way to do it. Can i know how can i cut all the file from the sftp /uploads/ dir and store to my local?

0 likes
3 replies
lostdreamer_nl's avatar

you can't, you'll need to copy them (as you are now) and then delete the old versions (this is how cut / paste works as well so it's not really any different)

Crazylife's avatar

@lostdreamer_nl Meaan that after loop and save the file then just call delete() function to delete related file right?

lostdreamer_nl's avatar

correct, or within the loop (just after you've copied the file to the other disk) Something like:

$files = $this->getFilesFromOriginalDisk();
foreach($files as $file) {
    $this->copyFileToOtherDisk($file);
    $this->deleteFileFromOriginalDisk($file);
}

Please or to participate in this conversation.