SSH transfer directories recursively from one server to other server

Here is one of the amazing use of wget command.

wget command can be used to copy files from one server to the other.

Prerequesites:
1. FTP credentials of old server
2. Shell access of the new server  (or ability to invoke system commands using PHP or any other high level or scripting language, this may timed out if the source if too large)

Run below command on your new server.

wget -r ftp://<USERNAME>:<PASSWORD>@<IP_OR_HOSTNAME>/<DIR>/*

Replace the username, password, IP/Host, directory locations with your own.

Using the above command you'd be able to copy the files and directories from your older server to new server.

Another useful command when you want to download from a location accessible on web

wget --mirror -p --convert-links -P /var/www/XXXX/ http://SITE_URL/pdf/

--convert-links flag will ask wget to follow all the URLs on page and download them

What if your source host allows SFTP connections only?

Well, we still have luck to download files using a different command.

Copy from SFTP

1. SSH on the destination host (where you want to copy)

2. Connect via SFTP to source host. Issue below commant (replace the parameters with yours)
lftp sftp://user:password@host.com/path/path/

cd - can be used to browse remote path
lcs - can be used to browse local path  (in our case the target host)

3. cd SOURCE_DIR_ON_REMOTE
lcd DESTINATION_DIR_ON_LOCAL

4. Now below command can download the files
mget *


-- Try at your own risk.