Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lakazai's avatar

FTP move folder in another server to another server

I have 3 server:

main server: laravel8, ubuntu 18.04, php7.4.
another server A: ubuntu 18.04, FTP server installed
another server B: ubuntu 18.04, FTP server installed

i want make command laravel (main server)

  • move folder from server A to server B
  • delete that folder in server A after move complete

Thanks!

0 likes
8 replies
trin's avatar

i think u can use

copy('ftp://user:[email protected]/path/to/file', 'ftp://user:[email protected]/path/to/file')

or

file_put_contents('ftp://user:[email protected]/path/to/file', file_get_contents('ftp://user:[email protected]/path/to/file'))

for copy files.

in total you can use standart Storage class for list ftp files, copy from ftp to ftp as i says and remove from ftp with Storage.

some kind of vinaigrette... but i think it is simplest and fastest method.

1 like
sr57's avatar

With ftp you have do 'double move*' file per file all your files in your folder (and sub folders if any)

  • retrieve the file from A to your main server and then put it on your server B
  • check for any error

And the end, if no error, delete folder in A

https://github.com/harishanchu/Laravel-FTP

Couldn't you install and use ssh/scp/rsync? It should be easier, more secure and more reliable.

2 likes
lakazai's avatar

thanks for reply if use use ssh/scp/rsync, how it works (i want control with laravel command + schedule)

lakazai's avatar

because move folder in another server to another server. then

shell_exec('ssh root@serverB rsync OPTION SourceDirectory_or_filePath user@serverA:Target')

It will be complicated if the number of files is large.

sr57's avatar

Hi @trin

and for me +1 for 'some kind of vinaigrette' :-)

1 like
sr57's avatar

test your command drectly first (have ssh log without passwd)

It will be complicated if the number of files is large.

Use job in Laravel for such task.

1 like

Please or to participate in this conversation.