How To: Transfer Files Over SSH with SCP

In this article, you will learn how to transfer files over SSH by using ‘scp’. If you need to transfer files over a network, this is one way to do so. There are numerous other options to transfer files over a network, and this is just one of them. Feel free to leave a comment sharing other ways you use to transfer files over SSH.

We have had quite a number of articles about SSH. It stands for “Secure Shell” and you can click to find a collection of SSH articles. If you’re entirely new to SSH, you’d probably enjoy learning how to install/enable SSH. As mentioned, there have been a bunch of articles covering this subject.

Today, we’ll be using ‘scp’, which defines itself as:

OpenSSH secure file copy

It shares quite a bit of similarity with the ‘cp’ command, a command we oddly haven’t covered yet. That’s not too important. We’ll eventually get to that article and maybe remember to link back to this one. What’s important to know is that it shares some similar features and syntax.

So, today we’re going to use ‘scp’ to transfer files over SSH, over a network. It’s a pretty good skill to know, as copying files is probably the 2nd most frequently used feature over SSH, with device management being first. At least it’d be 2nd most for me, I’m not sure what you all do with it.

Transfer Files Over SSH with scp:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

You’re also going to need a device you can SSH into, and I can’t really help you with that. You can always install OpenSSH on your desktop and practice by using SSH over localhost. 

Now, with your terminal open, it’s time to transfer a file. The very most basic command to copy a file to the remote server would be:

You can also copy multiple files to the remote server:

You can copy all files from the directory you’re in (on the local device) easily enough. It’s just our beloved asterisk.

If you want to copy the files from the folder in AND the files from the folders in that directory (recursively), then the command just requires a -r flag.

You can actually go the other direction. If you want to transfer remote files to your local device, then you’d be looking at this command:

From that, you can use the above commands, extrapolate if you will, for ways to transfer the file to your local device from the remote device. It’s not terribly difficult, and ‘scp’ is something everyone should know if they’re working with remote computers on a regular basis.

By the way, setting up SSH on your computer isn’t a bad idea. Sometimes a malfunctioning computer can be accessed via SSH when nothing else will work. I have SSH installed (and secured) on pretty much every computer in the house.

Closure:

See? Now you know how to use ‘scp’ to copy files over a network via SSH. It’s a pretty awesome skill to have and one you may need until the end of time, or at least as long as Linux lasts as an operating system – which should be quite a long time. So, it’s in your best interests to learn how to use ‘scp’ with at least a basic level of skill.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Start A Quick Python Server

Today’s article is going to show you how to transfer files between computers by using a quick Python server. It’s remarkably easy! It’s a temporary server (usually) and lasts only as long as you need it to.

Why would you do this? Well, you can transfer files from one computer to another. It also functions as an HTTP server which makes it easy to test things like simple web pages quickly and easily.

Are there better options? Quite probably. If you want to transfer a single file, then SCP is a good way to go about it. If you want to transfer multiple files, you could setup SFTP. If you want to test web pages, you can likely just write the files locally and then open them up with the browser of your choice.

You have options! And, thankfully, Linux provides all sorts of options – including setting up a quick Python server. As I said, it’s actually pretty easy.

A Quick Python Server:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

The first command I want you to run will let us know what version of Python you have installed. Many distros have (at present) moved onto version 3, but some still have Python 2 installed. So, for that information you just run:

Now, if you have Python v. 2.x, you would use this command:

If you’re using Python v. 3.x then the command you’d use is:

(If you’re curious, the -m is telling Python which module to open.)

Anyhow,  you can now connect to your server with the following command:

Read how to find your IP address. Instead of an IP address, you can also use your hostname.

Anyhow, you  now have a server running on port 8000. If you want to, you can also change the port number. This is the same for both commands. In both cases, just append your chosen port number to the command. Like this:

It’d look a little like this:

See? It's a different port number.
Note the changed port number. You should probably avoid reserved ports.

When you’re done with the quick Python server, you can just close it by pressing CTRL + C. If you’re planning on running it long term, you can always run the command with nohup. If applicable, you may also need to open the port in your firewall.

Like I said, it’s a quick and easy server in Python. You definitely wouldn’t want to use this as a public facing server, but it’s fine for quick tasks. Feel free to leave a comment letting folks know how you use this in  your day-to-day tasks.

Closure:

There you have it, another article said and done! The site is going well and the schedule seems to be working well enough. It’s a bit demanding to write one every other day, but that’s what I said I’d try to do. So far, so good!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.