How to Download Files from FTP Server Using Wget on Ubuntu
This article provides a step-by-step guide on retrieving files from an FTP server using the wget command in Ubuntu. You will learn the basic syntax, how to handle authentication credentials, and essential flags to manage your downloads effectively without needing a graphical interface.
Prerequisites
Ensure you have access to a terminal window on your Ubuntu system.
The wget utility is typically pre-installed. If it is
missing, install it by running:
sudo apt update
sudo apt install wgetBasic FTP Download
To download a file from an anonymous FTP server, use the following command structure. Replace the URL with the actual path to your file.
wget ftp://ftp.example.com/path/to/file.zipThis command initiates the connection and saves the file in your current working directory with its original name.
Downloading with Authentication
Many FTP servers require a username and password. You can provide these credentials directly in the command using specific flags.
wget --ftp-user=your_username --ftp-password=your_password ftp://ftp.example.com/file.zipFor security, avoid using this command in shared environments where command history is visible. You may be prompted to enter the password interactively depending on your shell configuration.
Useful Wget Options for FTP
You can customize the download behavior using various flags:
- Change Output Filename: Use
-Oto save the file with a specific name.bash wget -O newname.zip ftp://ftp.example.com/file.zip - Resume Broken Downloads: Use
-cto continue downloading a partially completed file.bash wget -c ftp://ftp.example.com/largefile.iso - Recursive Download: Use
-rto download entire directories.bash wget -r ftp://ftp.example.com/folder/
Security Considerations
Standard FTP transfers data in plain text, including credentials. For
sensitive data, consider using SFTP or FTPS if the server supports it.
While wget supports FTPS, using sftp or
scp commands is generally recommended for secure
shell-based file transfers.
By mastering these commands, you can efficiently automate file retrieval tasks on your Ubuntu machine directly from the command line.