FTP(File Transfer Protocol) is widely used and oldest application layer protocol used for file transfer between systems/devices.
By default, port 21 is used for FTP connection establishment, but internally some random port is used for actual file transfer. FTP works in client/server or local/remote model. From the system we connect is called client/local and the system we try to connect is called server/remote.
As FTP is not considered a secure protocol anymore, we have two secure ways to transfer files
FTPS – FTP over secure TLS/SSL connection
SFTP – Secure FTP using SSH. Now a days, SFTP is widely used in enterprises. This uses port 22, by default.
Let’s try to understand how FTP is used in command line. For connection to a remote system, we can use commands, like
#ftp
#open [remote system name / remote system ip address]
or
#ftp [remote system name / remote system ip address]
Once you are connected to the remote system, it will ask you to provide login credentials for that server like below, and you need to enter the login user name and password.
Name:
Passord :
Once you are successfully logged in into the remote system, you are ready for file transfer. For file transfer between the local and remote systems, we can use
> get [file_name] # Get a single file from remote to local
> get [file_name] [new_filename] # Get a single file from remote to local with new_filename
> mget [file_name_1] [filename_2] # Get multiple files from remote to local
> put [file_name] # Put a single file from local to remote
> put [file_name] [new_filename] # Put a single file from local to remote with new_filename
> mput [file_name_1] [filename_2] # Put multiple files from local to remote
There are lots of other things you can do or command you can execute, like
> ls #List the contents of current directory on remote system
> cd [directory_name] # Change the working directory on remote system
> cdup # Change to the parent directory on remote system
> chmod [file_name] # Chnage file permission on the remote system
> mkdir [new_directory_name] # Create new directory in remote system
> bye/quit # Exit from remote system
One thing you might have noticed, once we are logged in into the remote system, commands we executed are related to remote systems. But we have commands or ways to execute commands corresponding to local system, like
> lcd [path] # Change current directory in local system
or
> ![command] # Execute [command] corresponding to local system
I tried to share very basic knowledge to start with FTP in command line. You might need to check if all required packages/libraries are installed on your local and remote systems, before you start. Also, like I said, FTP is not secure so try to use secure FTP to avoid any security risk.