- [Instructor] In the previous video, we looked
at running commands on our remote host with SSH.
We're talking about transferring files through the network.
This video discusses how to transfer files using
commonly used protocols, FTP, SFTP, RSYNC and SCP.
The major drive of a networking
of computers is the resource sharing
and file sharing is the most prominent shared resource.
There are different methods by which we can transfer files
between different nodes on a network.
The commands for performing transfer
over the network and mostly available
by default with Linux installation.
Files can be transferred by FTP, using the lftp command.
Files can be transferred
via an SSH connection using sftp,
further, we can use RSYN over SSH with the rsync command,
and transfer files through SSH using scp.
File transfer protocol, FTP,
is a very old file transfer protocol
for transferring files between machines on a network.
FTP can only be used if the FTP server is installed
on the remote machine.
FTP is used in many public websites to share files
and the service usually runs on port 21.
To connect to an FTP server and transfer files
in between, use lftp command, like so.
It will prompt for a password,
and then display a logged in prompt, as follows.
You can type commands in this prompt,
for example, to change to a directory, use CD directory,
to change the director of a local machine, use LCD.
To create a directory, use MKDIR,
to list files in the current direct on the remote machine,
use LS.
To download a file, use Get Filename, as follows,
lftp username@ftphost:-> get filename.
To upload a file from the current directory,
use put filename, as follows.
At FTP, username@ftphost:-> put filename
An lftp session can be terminated by using the Quit command.
Auto completion is supported in the lftp prompt.
Okay, so now let's go through additional techniques
and commands used to file transfer through a network.
Automated FTP transfer.
FTP is another command used for ftp based file transfer.
Lftp is more flexible for usage.
Lftp and the FTP's open an interactive session
with the user.
What if we want to automate file transfer instead
of an interactive mode?
We can automate FTP files transfers
by writing a shell script.
This script has the following structure.
Less than, less than, EOF, data, EOF.
This is used to send data through standard in
to the FTP command.
Video 1.5 of this course explains various methods
for redirection into standard in.
The minus I option of FTP,
turns off the interactive session with the user.
This line sets the username and password.
Binary sets the file mode to binary,
the N option tells FTP not to attempt
to automatically logging in
and use the username and password supplied.
Nice.
Now let's have a look at SFTP secure FTP.
SFTP is a FTP-like file transfer system
that runs on top of an SSH connection
and emulates as an FTP interface.
It doesn't an FTP server at the remote end
to perform file transfer,
but it requires an open SSH server
to be installed and running.
The SSH server runs at the default Port 22.
SFTP is an interactive command,
which offers an SFTP prompt.
These commands are used to perform a file transfer.
All other commands remain the same
for every automated FTP session with a specific host,
user, and password.
In order to run SFTP, use SFT usere@domainname.
Similar to LFTP, an SFTP can be terminated
by typing the Quit command.
Sometimes the SSH server will not be running
at the default Port 22.
If it's running at a different port,
we can specify the port, along with the SFTP,
using oPort.
For example, this command, oPort,
should be the first argument of the SFTP command.
Great.
Now let's move onto the RSYNC command.
RSYNC is an important command line utility
that is widely used for copying files over networks,
and for taking backup snapshots.
This is better explained in the backup snapshots
with RSYNC, video 6.7 of this course.
SCP, security copy program.
SCP is a file copy technique,
which is more secure
than the traditional remote copy tool, called RCP.
The files are transferred through an encrypted channel.
SSH is used over an encryption channel
and we can easily transfer files
to a remote machine using
SCP filename user@remotehost:/home/path.
This will prompt for a password,
and can be made password-less
by using the auto login SSH technique.
We'll discuss that in the next video.
File transfer using SCP doesn't require specific scripting.
Once SSH login is automated,
the SCP command can be executed
without an interactive prompt for the password.
Here, the remote host can be an IP address
or a domain name.
The format of the SCP command is,
scp SOURCE DESTINATION.
Source or destination can be in the format
of a path, for example.
This command copies a file from the remote host
to the current directory with the given filename.
If SSH is running a different port than 22,
use the minus oPort, with the same syntax, SFTP.
Recursive copying with SCP.
By using SCP, we can recursively copy a directory
between two machines on a network
with the minus R parameter.
Here's the command that we use.
SCP can also copy files by preserving permissions
and modes by using the minus P parameter.
So that's all for this video.
We've learned ways to transfer files
through the network.
In the next video, we'll explore password-less
auto-login with SSH.