How to copy a file or directory from a remote server to your local computer

Written by teamember02
Updated 8 months ago
  • To copy a file from a remote server to your local computer you need to use the scp command.
    To use the scp you need to follow this syntax;
    - To copy a file;
    scp user@remotehost:/path/to/remote/file.txt /local/destination/
    - To copy a directory;
    scp -r user@remotehost:/path/to/remote/directory /local/destination/

    Example:
    First I create a new directory named donald in server 4 as shown below;

    Next I exit from the server so as to copy the directory donald into my local computer.

    If you can see I replaced user@remotehost with royce@server4.anomicatech.com, /path/to/remote/directory/ with ~/donald and /local/destination/ with ~/Downloads. This simply means I copied the directory donald present in my home directory (~/) from my user royce in the remote server server4.anomicatech.com to my local computer in the directory ~/Downloads/ as shown below

    Finally, as you can see you donald/ is found locally in my ~/Downloads.

    NB: You can allow authentication with your remote server to allow copies via by password authentication or by pubkey authentication. But in my example I did by password authentication. 
     
Did this answer your question?