upload and download file in ftp

How to Upload & Download Files From FTP in Linux

FTP is a popular tool used by web developers and system administrators to transfer files to and from their websites to their own workstation or laptop. There are plenty of third-party tools that allows you to connect to your FTP server to send/receive files. In this article, we will look at how to upload & download files from FTP in Linux using simple command line arguments. There is no need to install/download any tool for our example.


How to Upload & Download Files From FTP in Linux

Here are the steps to upload & download files from FTP in Linux.


1. Connect to FTP server

Let us say your FTP server is runs at IP address 54.43.32.21. Open terminal and run the following command to connect to your FTP server. We will use ftp command for this purpose which is already installed by default in almost all Linux distributions.

$ sudo ftp 54.43.32.21

If your FTP runs on a subdomain like ftp.example.com you may replace ip address and port number above with the subdomain.

$ sudo ftp ftp.example.com

In both the above cases, you will be prompted to enter password for your FTP username and password. After successful authentication, you will see the ftp prompt as shown below.

ftp>


2. Upload Single File to FTP

You will be logged into your home directory. Next, navigate to the folder where you want to upload your file.

ftp> cd uploads

Use put command to upload file from your local machine, followed by file location. The following command will upload a single file to your FTP folder.

ftp> put c:\file\data.txt


3. Upload Multiple Files to FTP

If you want to upload multiple folders, you need to use mput command along with wildcard characters such as *. The following command will upload all .txt files from c:\file folder on your local machine. It can be used to upload multiple files at once to your FTP server. Before we issue mput command, we use lcd command to navigate to our required local folder.

ftp> lcd c:\\files
ftp> mput *.txt


3. Download Single File from FTP

If you want to download single file from FTP, use get command. Navigate to the folder from where you want to download your file, and issue get command along with filename,

ftp> cd downloads
ftp> get data.txt

The file will be downloaded to your local ftp folder.


4. Download Multiple Files from FTP

If you want to download multiple files from FTP, use mget command to download them along with wildcard characters to specify the filenames. Navigate to the folder from where you want to download files. The following command will download all .txt files from downloads folder.

ftp> cd downloads
ftp> mget *.txt

That’s it. In this article, we have learnt how to easily upload & download one or more files to and from your FTP server without using any third-party tool. FTP operations are very common when you are working in a software development team and the above commands will help you easily move files between your local machine and FTP server. The benefit of using above commands is that you may also embed these commands in shell scripts to automate them, or schedule them as cron jobs to regularly run them.

Also read:

How to Delete Files Older Than X Days in Linux
How to Check Inode Usage in Linux
How to Find Inode Number of File in Linux
How to Convert HTML to PDF in PHP
How to Create Ext4 Filesystem in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *