Skip to content
Alona

Securely Transferring Files Over the Network in Linux

Linux2 min read

The command cp was a command I learned back when I was using MS-DOS! (My age is showing.) It was one of the things I learned from my father, a computer fanatic (he bought a lot of computers when we were growing up--he wasn't a computer science guy and I'm not sure why he just liked computers but I can understand that now). I learned this along with dir and mv (and that's all I can remember now).

Today, however, I learned something new and that is how to securely transfer files over the network in Linux using the scp and sftp commands in your local environment. I also learned the various GUI apps one can use to do the same.

scp and sftp (secure copy and ssh file transfer protocol, respectively) are commands available on a Mac, which is what I use. I don't care much about what's used on Windows so I'm not going to write those here. It's something like "PuTTY" (I started learning how to use computers on Windows but I haven't actively used one for about six years now and the last time I used it, it was because the computers in the lab I worked at--a chemistry lab--are all Windows, which I maintained, by the way as a chemist in that lab). Anyways, without using secure copy of ssh ftp, crendentials are also transferred over the network. This is like using ssh instead of telnet.

I loved finding out that with sftp, I can work with files in my local (Mac) and remote (Linux) environment in the same console. That blew my mind for a while. Here is how my console (I'm using iTerm on my Mac) looks like when I log in to my Linux server I got going at the IBM Systems Cloud for Enablement and Co-Creation.

1➜ ~ sftp cecuser@129.xx.xx.xxx
2
3Connected to 129.xx.xx.xxx.
4sftp> pwd
5Remote working directory: /home/cecuser
6sftp> lpwd
7Local working directory: /Users/alona
8sftp>

(I have my ssh key stored in my computer so I need not input my password, but normally, a user will be prompted for a password.) The prompt is sftp. pwd gives the remote working directory while lpwd gives the local working directory.

Typing in ls gives the files that are in my remote server.

1sftp> ls
2epel-release-latest-7.noarch.rpm lnxtraining
3support-scripts

And when I type in lls, it lists all the files in my local machine.

1sftp> lls
2Applications Public
3Box PycharmProjects
4Desktop VirtualBox VMs
5Documents
6Downloads
7Library
8Music
9Pictures
10Postman

To transfer files from the local machine to the server, we use the command put.

1sftp> lls
2x.txt
3sftp> put x.txt
4Uploading x.txt to /home/cecuser/x.txt
5x.txt 100% 23 0.2KB/s 00:00
6sftp> ls
7epel-release-latest-7.noarch.rpm lnxtraining
8support-scripts x.txt

You can see that the file x.txt got transferred to the remote server.

To exit from stfp, one merely types in exit.

scp on the other hand, is a little less useful for me as I need to know the source and destination of the file I want to transfer. So this is like working blind in the local environment, and shooting the file over to the Linux server via the scp command.

GUI apps available are Cyberduck, FileZilla, and WinSCP. Cyberduck is app for MacOS, and the others are for Windows and Linux. In the future, I plan to download Cyberduck and hopefully see how it works.