Copying files over the network.
Introduction
This lesson will introduce how to copy files over the network. You already know how to copy files from one location to another on the same system using cp
command. But if you want to copy files from your local work station to a Linux server or between Linux servers you need to use SCP or SFTP.
- SCP is Secure copy.
- SFTP is SSH file transfer protocol.
SCP and SFTP are both extensions of the secure shell protocol.
Command Line SCP/SFTP Clients
In order to use SCP or SFTP you need a client.
- Mac and Linux come with
scp
orsftp
command line utilities. - If you are running Windows, you can use the PuTTY Secure Copy client - pscp.exe and the PuTTY Secure File Transfer client - psftp.exe.
With scp
you need to know what files you want to transfer before running the command. The scp
command format is
scp <source> <destination>
If you are looking for a more interactive experience where you can examine the local files and remote files, use sftp
. The sftp
command format is
sftp <host>
For example: connect to reliawind server with username admin
$ sftp admin@reliawind
Graphical SCP/SFTP Clients
There are graphical clients as well.
- Cyberduck is popular for Mac and Windows.
- FileZilla runs on Mac, Windows, and Linux.
- WinSCP is a Windows only SCP and SFTP client.
FTP Command Line Utility
SCP and SFTP are not the only way to transfer files to remote system. Sometimes FTP, called file transfer protocol, is enabled. In such cases you can use the built-in FTP command line client on Linux, Mac, or a graphical client like WinSCP for Windows.
The ftp
command format is:
ftp <host>
Important: Just be aware that FTP is not a secure transfer protocol like SCP and SFTP. This means that your login credentials are sent in plain text over the network. The files that you upload and download are not encrypted either. If given the choice between SCP, SFTP or FTP, pick SCP or SFTP.
Examples
Example - SFTPAfter use sftp
connected to the remote server servername, you can use pwd
to check your current working directory on the server, and ls
to show all the files & directories in the current remote directory. If you precede those commands with an l , that's for local, lpwd
display your local working directory, and lls
will show files & directories in your current local directory.
$ sftp admin@servername admin@192.168.1.1's password: Connecting to servername sftp> pwd Remote working directory: /home/admin sftp> ls
Let's put a file test.txt onto the server. Then you can type ls
to check whether test.txt has been uploaded.
sftp> put test.txt Uploading test.txt to /home/admin/test.txt sftp> ls Applications Downloads Movies Public Desktop Dropbox Music node_modules Documents test.txt
To quit a SFTP client, type quit
.
sftp> quit $Example - SCP
With scp
you can copy from your local system to the remote system, but you need to know the source and destination. So in this example, our source file is test.txt and the destination is servername. You can append a colon (:
) at the end of the servername followed by a path name. For example: put this file in the tmp directory on the remote server.
$ scp test.txt servername:/tmp/ admin@192.168.1.1's password:
You could put the file in home directory using the home directory shortcut tilda (~
)
$ scp test.txt servername:~/
To check whether file has been transfered, you can do this with SSH or SFTP connection.
Example - FileZillaTo be added ...
Latest Post
- Dependency injection
- Directives and Pipes
- Data binding
- HTTP Get vs. Post
- Node.js is everywhere
- MongoDB root user
- Combine JavaScript and CSS
- Inline Small JavaScript and CSS
- Minify JavaScript and CSS
- Defer Parsing of JavaScript
- Prefer Async Script Loading
- Components, Bootstrap and DOM
- What is HEAD in git?
- Show the changes in Git.
- What is AngularJS 2?
- Confidence Interval for a Population Mean
- Accuracy vs. Precision
- Sampling Distribution
- Working with the Normal Distribution
- Standardized score - Z score
- Percentile
- Evaluating the Normal Distribution
- What is Nodejs? Advantages and disadvantage?
- How do I debug Nodejs applications?
- Sync directory search using fs.readdirSync