Search code examples
phpftpdownloadbackuphost

PHP download entire folder (recursive) via FTP


I currently have a very large site approximately 5gb in size with 60,000 files. The current host isn't doing much in the way of helping me transfer the site to the new host and what I was thinking was to make a simply script on my new host to FTP into the old host and download the entire public_html folder (recursively) to the new server. Is this possible and if so, does anyone have any links they could share to aid in this? Much appreciated.


Solution

  • There are probably better mechanisms to do what you want to do.

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

    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/
    

    The -P makes it easy to restart a stalled/dead download.

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

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

    The --continue makes it easier to restart a stalled/dead download.