Linux Command To Download File From Server To Local Machine

Most people prefer utilities like FileZilla or WinSCP when they need to transfer files to or from Linux/BSD servers. If the OpenSSH daemon is running on that computer, you can connect to it through the Secure/SSH FTP protocol (SFTP). The aforementioned utilities do make it easier to transfer files by offering a graphical interface, but you have to install and configure those programs.

  1. Download From Linux Command Line
  2. Linux Command To Download File From Server To Local Machine Shop
  3. Linux Command To Download File From Server To Local Machine Shops

SCP uses Secure Shell (SSH) to transfer data between client and remote server, it’s fast and secure. In this article, we will show you two common SCP copying examples: Copying data from your computer to remote server. Copying data from remote server to your computer. Normally, programs like winSCP are used to transfer data between Linux server and windows machine. In this article we will walk you through how to add key based authentication in winSCP. Later how to download file from EC2 to local machine.

Some purists prefer not having to install extra utilities. Other people simply prefer the command line because it gives you more control and a faster way to tell the utility what you want it to do. But now there’s an extra reason to resort to the command line when you want to transfer files. Windows 10 started to include, by default, an OpenSSH client that lets you log in to Linux/BSD servers directly from Command Prompt.

This client also comes with a bunch of other utilities, and SFTP is among them. So, you can now also transfer files to Linux/BSD operating systems, directly from Command Prompt, without having to install anything on your Windows machine.

The sftp utility is also available on Linux machines and works the same way.

Related: Accessing Your Linux Server from Android

How to Log in with the sftp Command

If you’re on Windows, open Command Prompt. If you’re on Linux, open a terminal window.

To log in to a server with the sftp command, you use the exact same syntax as with the ssh command. If you’re unfamiliar with this syntax, read the tutorial linked in the introduction paragraph.

Example commands:

How to Download Files After You Log in with sftp

You can now enter commands at the sftp > prompt to interact with files on the server.

To download a file:

Example:

This will download to your current directory, the one you were in locally before you logged in to the server. To download to a specific local directory (on Windows):

Get

Example

On Linux you simply use Unix type paths (forward slash instead of backslash):

Note: even if you (incorrectly) use forward slashes for Windows paths, in sftp, it seems the utility will understand them.

Download From Linux Command Line

Paths can also be relative. This means that if you already were in C:UserJohn when you opened Command Prompt, you can download to your desktop (C:UserJohnDesktop) with:

The remote paths can also be relative, which means that if you log in with sftp john@203.0.113.1, you will already be in the directory “/home/john,” so you can use this to download “/home/john/file:”

This would download “/home/john/file” to “C:UsersYourUserDesktopfile.”

To copy directories, you have to add the -r parameter to the command, which stands for recursive.

Remember to add a name for the new directory you want to create locally, like “Desktopbin” in this case. If you would use get -r /bin Desktop, files would be copied directly on the Desktop. It’s the files that are copied, not the directory itself.

Related: 7 Useful Features of FileZilla and Why It Is the Best FTP Application

How to Upload Files After You Log in with sftp

Uploading files or directories follows the same principles. The only exception is that paths are reversed, meaning you first specify the local file/directory and then the remote path.

On Windows:

On Linux:

When uploading directories (recursive), remember that the same rule as in the previous section applies: it’s actually the files in the directory that are copied, not the directory itself. So specify a new name for a directory you want to copy those files to.

This would create a new directory called “bin” on the remote side.

To exit the sftp shell, simply type:

How to Resume Transfers and Use Paths that Contain Spaces

When you transfer a large file, if it gets interrupted, you can resume by replacing the previous command with reput and reget instead of put and get. Just make sure you use the exact same paths you used last time, so that source and destination match exactly.

To resume directory transfers, just add the -r parameter

Linux Command To Download File From Server To Local Machine Shop

If the path to a file contains spaces, put it within quotes.

This won’t work:

Command

But this will:

Linux Command To Download File From Server To Local Machine Shops

(Yes, you can actually find the Witcher 3’s soundtrack there if you have it installed on Steam.)

Conclusion

This covers the most important things you have to know about sftp. If you find that you have a need for learning more, you can read the complete sftp command manual online.

Is this article useful?

Ebooks

Comments are closed.