— Linux — 2 min read
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
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
sftp commands in your local environment. I also learned the various GUI apps one can use to do the same.
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 email@example.comConnected to 129.xx.xx.xxx.4sftp> pwd5Remote working directory: /home/cecuser6sftp> lpwd7Local working directory: /Users/alona8sftp>
(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
pwd gives the remote working directory while
lpwd gives the local working directory.
ls gives the files that are in my remote server.
1sftp> ls2epel-release-latest-7.noarch.rpm lnxtraining3support-scripts
And when I type in
lls, it lists all the files in my local machine.
1sftp> lls2Applications Public3Box PycharmProjects4Desktop VirtualBox VMs5Documents6Downloads7Library8Music9Pictures10Postman
To transfer files from the local machine to the server, we use the command
1sftp> lls2x.txt3sftp> put x.txt4Uploading x.txt to /home/cecuser/x.txt5x.txt 100% 23 0.2KB/s 00:006sftp> ls7epel-release-latest-7.noarch.rpm lnxtraining8support-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
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
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.