DEV Community

Cover image for Replace FTP with the SCP command in the terminal
Waqar Ahmed
Waqar Ahmed

Posted on • Originally published at Medium

Replace FTP with the SCP command in the terminal

SCP comes in handy to copy files to a remote server from a computer or vice versa. You can also copy server files to another server.

All you need is your server’s IP address and user credentials to start copying. Here are some common SCP commands use cases.

Copy file from your computer to a remote server

scp file.zip user@hostip:/home/directory
Enter fullscreen mode Exit fullscreen mode

This command will copy file.zip in your terminals present working directory to the home directory of the server.

Copy file from a remote server to your computer

scp user@hostip:/home/directory/file.zip ~/Downloads
Enter fullscreen mode Exit fullscreen mode

You are copying file.zip from the server’s home directory to your local downloads folder.

SCP between two remote hosts from your computer

Another use case of the SCP command is during site migration to a new server. Zip your site’s root directory and copy it to the new server.

Provide login credentials and file paths of both servers to SCP in your computer’s terminal.

scp user@remotehost1:/home/file.zip user@remotehost2:/home
Enter fullscreen mode Exit fullscreen mode

SCP Options

Mention transfer port

Add -p flag to add port of remote host

scp -p 1122 file.zip user@hostip:/home/directory
Enter fullscreen mode Exit fullscreen mode

Use file compression

Add a -C flag to enable the gzip compression in SSH transfer

scp -C localfile.zip user@hostip:/home/directory
Enter fullscreen mode Exit fullscreen mode

More SCP Options

-v Verbose SCP operation
-p <port> Mention remote host port
-P Save the file’s modification and access times
-r Copy recursively
-c <cipher> Specify the cipher for data encryption

So if you are still using an FTP client, use the SCP command in the terminal for a secure transfer.

Top comments (0)