Web & Software Developer

Transfer Files From Server to Server via Terminal

This is a quick way to transfer or move files from one server to another server via the command line. This uses SSH. Before you begin, make sure your web host allows SSH connections. Some hosts require that you first enable SSH before they give you access.

This works in a linux terminal (or PuTTY on Windows).

  1. Make an SSH connection to the source site (the site that you want to copy files FROM).
  2. Navigate to the directory containing the files (or directory) that you want to move.
  3. Use tar to package the files which you want to move:

    For 1 directory (change ‘dir’ to the name of your own directory):

    tar -cvzf dir.tar.gz dir 

    For multiple files (change ‘file1 file2 file3’ to the name of your own files):

    tar -cvzf files.tar.gz file1 file2 file3 
  4. Check if your archived file was created:

    ls -lah *.tar.gz 
  5. Close the SSH connection:

    exit 
  6. Make an SSH connection to the destination site (the site that you want to copy files TO). Navigate to the directory in which you want to place the files.
  7. Import the packaged file from the source site:

    Edit the path according to where your package resides, which is where you navigated to in step 2. Edit “dir.tar.gz” to the name of your package which you created in step 3.

    wget http://sourcesite.com/dir.tar.gz  
  8. Extract the package:

    tar -xvzf dir.tar.gz 
  9. Remove the archive package:

    rm -f dir.tar.gz 
  10. Close the SSH connection:

    exit 
  11. Make an SSH connection again to the first server so that we can delete the archive package. Navigate to the directory where you created the package.
  12. Remove the archive package:

    rm -f dir.tar.gz 

By

We've One Response

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]