Securely Transfer Files Over The Network
SFTP, or Secure File Transfer Protocol, is a network protocol that provides file access, file transfer, and file management functionalities over any reliable data stream. It is typically used with the SSH protocol to provide secure file transfer, but it can be used with other protocols as well.
This command will initiate an SFTP session with the
remote-host. It will be prompted to enter the password for the
username connecting with.
Once in the SFTP session, we can use
ls to list files,
cd to change directories,
get to download files, and
put to upload files. Here are syntax for reference:
|Server Actions||Command Syntax|
|Show current directory|
|Delete file or directory|
|Rename file or directory|
|Client Actions||Command Syntax|
|Change local directory|
|List local files|
|Create local directory|
|Show current local directory|
|Upload file to server|
|Download file from server|
|Wildcards supported||Use |
Secure Copy Protocol (SCP) is a means of securely transferring computer files between a local and a remote host or between two remote hosts. It uses SSH for data transfer and provides the same authentication and security as SSH.
push file) The example of using SCP to transfer files:
scp "/path/to/localFile" username@remote-host:/path/to/remoteDirectory
This command will copy the file
localFile from local machine to the
remoteDirectory on the
push directory) The example of using SCP to transfer directory, the
-r (recursive) option is require:
scp -r /path/to/localDirectory username@remote-host:/path/to/remoteDirectory
pull file) To copy a file from the remote host to local machine:
scp username@remote-host:/path/to/remoteFile /path/to/localDirectory
|Preserves the original file's permissions and metadata.|
|Recursively copies directories and their contents.|
|Limits the transfer speed to the specified rate in Kbps. For example, |
TAR over SSH provides end-to-end encryption, which means that the contents of the transferred files are protected from unauthorized access. It also allows you to transfer multiple files or directories in a single archive, which can be more efficient than transferring them individually.
tar czf - /path/to/directory | ssh user@remotehost "tar xzf - -C /remote/path"
This command will create a compressed tarball of the directory located at
/path/to/directory, and then pipe the output to the
ssh command, which will connect to the remote host as
user and extract the contents of the tarball to the directory located at
|Create compressed tarball of a directory|
|Pipe output to SSH command||`||`|
|Connect to remote host|
|Extract tarball to specify directory|
These are the fundamentals of using
tar on Linux. They are robust tools that, once mastered, can greatly aid in managing and transferring files between systems.