PHP uploads a whole folder (recursive) via FTP

I currently have a very large site about 5 GB in size with 60,000 files. The current host doesnโ€™t really help me transfer the site to the new host, and I thought it was easy to make a script on my new host on FTP to the old host and upload the entire public_html folder (recursively) to the new server. Is this possible, and if so, does anyone have any links that they could share to help with this? Very much appreciated.

+2
source share
3 answers

There are probably better mechanisms for doing what you want to do.

First, can you use sftp or scp from one host to another?

 scp -R username@oldhost :path/to/directory/ /path/to/destination/directory 

or

 sftp username@oldhost # then use 'get -r' to download recursively 

or

 rsync -avz -P username@oldhost :/path/to/directory/ /path/to/destination/directory/ 

-P makes it easy to reload boot / dead boot.

If good tools won't work, see if wget installed:

 wget --mirror --continue --ftp-user=username ftp://oldhost/path/to/directory/ 

--continue makes it easy to reload a loaded / dead boot.

+3
source

If there are many files, I highly recommend that you create a .tar.gz archive. I don't know what limitations for php you have, but you can try this in php:

 $archive = "backup.tar.gz"; $directory = "./www"; exec( "tar -czf $archive $directory"); 

Then you can simply download 1 single zziped archive via http / ftp or any other way.

+1
source

Yes, you can do it in pure PHP!

I just released two new libraries to do such things in FTP / SFTP

Recursively copy files and folders to a remote SFTP server (if local_path ends with the contents of a slash folder, otherwise the folder itself loads)

 Ftp::upload_dir($server, $user, $password, $local_path, $remote_path, $port = 22); 

Download the directory from the remote FTP server (if remote_dir ends with the contents of the folder with a slash directory, otherwise load the folder)

 Ftp::download_dir($server, $user, $password, $remote_dir, $local_dir, 

$ port = 22);

If you want to look at the code, you will see recursive functions that do magic;)

0
source

Source: https://habr.com/ru/post/885822/


All Articles