How Do I Use SCP to Transfer a Directory in Linux?

2

This instructional explains methods to simply switch directories the usage of the Linux scp (Secure Copy Protocol) command.

Despite the Linux scp command being deprecated and changed by way of SFTP and RSYNC, its use is extensively followed. Even after being deprecated and changed, almost certainly SCP is the most typical way to switch information. Yet, its use isn’t professionally beneficial. That’s why after the scp directions to obtain and add directories, I added directions to do the similar the usage of the sftp command.

Download and Upload Directories Using scp

Uploading or fetching directories with scp is very similar to importing or downloading common information. The handiest distinction is the -r flag you want so as to add for directories to be transferred recursively.

The first instance of this instructional has the next traits you want to interchange:

  • The username used to log in at the faraway instrument is kali.
  • The faraway IP deal with is 168.1.100.
  • The listing to obtain is called linuxhintdir.

You will wish to exchange the username, IP deal with, and listing names in step with your situation.

The instance under invokes the scp command with the -r (Recursive) flag to specify we wish to obtain a listing and no longer a normal document. The scp command and the -r flag are adopted by way of the [email protected]/Host. Then, it’s adopted by way of a colon and the trail to the listing you wish to have to obtain. Whatever you wish to have to add or obtain a listing, the positioning the place you wish to have to save lots of the listing or common document is at all times specified on the finish of the command. In this example, the linuxhintdir listing might be saved within the /root listing.

The syntax is:

scp -r @:

In my case:

scp -r [email protected]:linuxhintdir/ /root/

Note: Files and directories used on this instructional are empty.

As you’ll be able to see, the document was once transferred accurately.

Uploading a listing the usage of SCP calls for a an identical syntax. The distinction, as I stated up to now, is you want to sort the trail the place to save lots of the listing on the finish of the command.

This is for the reason that scp command was once designed to be an identical as imaginable to the cp Linux command.

In the next instance, a listing named localdir situated within the present listing is copied to the faraway host’s default location, the kali person house listing. By default, should you don’t specify a patch after the colon, the default trail for information to be copied is the house listing of the person you authenticated.

After invoking SCP, upload the -r flag to specify you’re shifting a listing and no longer a normal document. Then, specify the listing you wish to have to ship adopted by way of : as proven within the instance under:

scp -r localdir [email protected]:

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800315 277 How Do I Use SCP to Transfer a Directory in

As you’ll be able to see within the following screenshot taken from the faraway host, the listing was once copied recursively:

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800315 989 How Do I Use SCP to Transfer a Directory in

Downloading and Uploading Regular Files Using scp

As stated up to now, downloading and importing common information is nearly the similar as with directories with the exception of for the absence of the -r flag, which isn’t important.

To add a document, use the next syntax:

scp @:

Therefore, to add a document named linuxhintfile to the faraway default listing, referred to as the kali person house listing, I run the next command:

scp linuxhintfile [email protected]:

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800316 675 How Do I Use SCP to Transfer a Directory in

To obtain a document, the syntax is the next:

scp @:

The following instance displays methods to obtain a document named linuxhintfile, to retailer in the house listing of the faraway person named kali, and put it aside within the native person’s Downloads listing.

scp [email protected]:linuxhintfile ~/Downloads

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800316 298 How Do I Use SCP to Transfer a Directory in

As proven, the document was once transferred accurately.

Download and Upload Files and Directories Using sftp

Downloading and importing information and directories the usage of SFTP will also be easy as with SCP.

The following manner displays methods to obtain a document situated within the faraway subdirectory named dir. The document might be in the community stored within the /tmp/linuxhint2 listing.

sftp [email protected]:dir/document /tmp/linuxhint2

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800317 716 How Do I Use SCP to Transfer a Directory in

Downloading directories is identical procedure. The instance under displays methods to obtain the dir listing to the present location specified with a dot:

sftp -r [email protected]:dir/ .

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800317 131 How Do I Use SCP to Transfer a Directory in

Uploading directories isn’t as simple as with SCP and the syntax adjustments. This is as a result of you want to connect with the SFTP server to and run the put command to add the document.

In the instance under, the document named linuxhintfile is uploaded to the dir subdirectory at the faraway host:

sftp [email protected]:dir

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800318 882 How Do I Use SCP to Transfer a Directory in

Uploading directories additionally calls for imposing the -r flag for recursive transference. However, when importing, the -r flag should be positioned after the put command, as proven within the instance under by which the listing linuxhintdir is uploaded to the faraway subdirectory named dir.

sftp [email protected]:dir

How Do I Use SCP to Transfer a Directory in Linux? How Do I Use SCP to Transfer a Directory in Linux? 1630800319 9 How Do I Use SCP to Transfer a Directory in

As you’ll be able to see, the listing was once uploaded effectively. That’s how you’ll be able to obtain and add information and directories in Linux the usage of scp instructions or the extra beneficial sftp instructions.

Conclusion

As you’ll be able to see, copying directories in Linux remotely the usage of the scp command is lovely easy. The scp command is thought of as essentially the most user-friendly way to switch information between units, and it was once as soon as thought to be safe as its title, Secure Copy Protocol, signifies. Currently, the scp command is out of date because of vulnerabilities and should no longer exchange more secure choices like SFTP and RSYNC. The sftp command may also be utilized in interactive mode, which wasn’t defined on this instructional, however you’ll be able to learn it at https://linuxhint.com/sftp_linux_command_line/. All methods supporting SCP will have to give a boost to SFTP, so availability will have to no longer be an issue. In long term tutorials, the RSYNC choice might be defined, so stay following this weblog for extra Linux pointers and tutorials.

Thank you for studying this SCP instructional, I am hoping it was once helpful to you.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More