Master LLMs with our FREE course in collaboration with Activeloop & Intel Disruptor Initiative. Join now!


How to use the SCP Command for File Transfer
Latest   Machine Learning

How to use the SCP Command for File Transfer

Last Updated on July 20, 2023 by Editorial Team

Author(s): Garima Nishad

Originally published on Towards AI.

Using File Transfer on Linux U+007C Towards AI

SCP (secure copy) command in Linux can be confusing, let me make this a bit easier for you

In this blog post, I’m going to show you how you can use the SCP command to copy your files or directories from your local machine to a remote server. So let’s say I have a remote server( shown below):

This one is my local machine,

Now let’s say and I want to transfer the file from my local machine to a remote server. So, first of all, let’s see what are the options we have with the SCP command by typing “scp” in the terminal.

This will show you all the options which you can use with the SCP:

As documentation states that

  • -c cipher
    Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1).
  • -F ssh_config
    Specifies an alternative per-user configuration file for ssh. This option is directly passed to ssh(1).
  • -i identity_file
    Selects the file from which the identity (private key) for public-key authentication is read. This option is directly passed to ssh(1).
  • l limit
    Limits the used bandwidth, specified in Kbit/s.
  • -o ssh_option
    It can be used to pass options to ssh in the format used in ssh_config.

We may not use all these complex commands if we simply want to transfer the file. In that case, we just need to give the username and the host IP and then the file name.
For example, let’s say I have a folder called “idd” in one of my Desktop folders.

So I’m going to just CD to my folder first of all and then I will transfer this idd folder to the server from my home directory.

So I have a folder named “idd1” which I’m gonna copy to the remote server.

so we will use an SCP command and the IP of this remote server so to know the IP of the remote server you just say if config and then press enter

The IP address of the remote server is the one written right beside “inet” and then we also need the user so username in my case is “garima” which can be different in your case.

So now in your SCP command write your file name, so just give the file name in my case its “idd” and then the hostname which is “garima” in my case and then @ the IP address of the remote server.

Please note that if your file is a normal file you don’t need to add -r , it is only used for copying folder or directory

So, in whatever folder you want to transfer your files you just need to give the path of that after the colon (:) so, for example, I want to just transfer my files to the alice directory, then press enter.

scp -r idd1 [email protected]:/home/garima/alice

For the first time, it will ask you “are you sure you want to continue connecting?” you can just say yes for the first time and then press ENTER and then it’s going to need your remote server's password so the password you use to log into this remote server. Just enter your password then this file would be transferred.

There you have it, your files will be transferred in a flash.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓