The command to download a file in FTP is get
.
When working with an FTP (File Transfer Protocol) command-line interface, retrieving a file from a remote server to your local machine is a straightforward process. You employ the get
command, followed by the exact name of the file you wish to retrieve. Conversely, to upload files, the put
command is used, also followed by the file's name.
Understanding the FTP get
Command
The get
command is fundamental for downloading files from an FTP server. It initiates the transfer of a specified file from the connected remote server to your current local directory.
Syntax:
get [remote-filename] [local-filename]
[remote-filename]
: The name of the file on the FTP server you want to download. This is a required parameter.[local-filename]
(optional): The name you want to give the file once it's saved on your local machine. If omitted, the file will be saved with its originalremote-filename
.
How to Download a File Using FTP Command Line
Before you can use the get
command, you need to establish an FTP connection to the server. Here’s a step-by-step guide:
- Open your terminal or command prompt.
- Connect to the FTP server:
ftp [ftp.your-domain.com]
You will then be prompted to enter your username and password.
- Navigate to the correct directory on the remote server (if needed):
cd /path/to/remote/directory
- Navigate to your desired local directory (if needed):
lcd /path/to/local/directory
- Set the transfer mode (optional but recommended):
- For text files (e.g.,
.txt
,.html
,.php
), useascii
. - For binary files (e.g.,
.zip
,.jpg
,.pdf
,.exe
), usebinary
.binary
or
ascii
Setting the correct mode prevents file corruption, especially for binary files.
- For text files (e.g.,
- Execute the
get
command to download the file:get mydocument.pdf
This will download
mydocument.pdf
from the remote server to your current local directory.
If you want to save it with a different name locally:get mydocument.pdf new_name.pdf
- Exit the FTP session:
bye
or
quit
Practical Insights and Advanced Commands
Beyond a single file download, the FTP command line offers more powerful features:
- Downloading Multiple Files (
mget
): If you need to download several files that follow a pattern, you can usemget
with wildcards.mget *.jpg
This command will prompt you for confirmation before downloading each
.jpg
file in the remote directory. - Listing Files: To see what files are available on the remote server, use the
ls
ordir
command.ls
- Transfer Modes: Understanding ASCII and Binary modes is crucial for successful transfers.
- ASCII Mode: Used for plain text files. It handles character set conversions between different operating systems.
- Binary Mode: Used for all non-text files (images, archives, executables, videos, etc.). It transfers the file byte-for-byte without any conversion, preserving its integrity. Always use binary mode for files other than pure text.
- Checking Current Directories:
pwd
: Shows the present working directory on the remote server.lpwd
: Shows the present working directory on your local machine.
Common FTP Commands Overview
Command | Description | Example Usage |
---|---|---|
open |
Connects to an FTP server. | open ftp.example.com |
user |
Specifies the username for logging in. | user myusername |
pass |
Specifies the password for logging in. | pass mypassword |
ls |
Lists files and directories on the remote server. | ls or dir |
cd |
Changes the current directory on the remote server. | cd public_html |
lcd |
Changes the current directory on the local machine. | lcd /Downloads |
get |
Downloads a single file from the remote server to the local machine. | get remote_file.txt |
put |
Uploads a single file from the local machine to the remote server. | put local_file.zip |
mget |
Downloads multiple files from the remote server using wildcards. | mget *.doc |
mput |
Uploads multiple files from the local machine using wildcards. | mput *.bak |
binary |
Sets the transfer mode to binary. | binary |
ascii |
Sets the transfer mode to ASCII. | ascii |
delete |
Deletes a file on the remote server. | delete old_file.log |
mkdir |
Creates a new directory on the remote server. | mkdir new_folder |
rmdir |
Deletes an empty directory on the remote server. | rmdir old_folder |
bye |
Closes the FTP connection and exits. | bye or quit |
For more detailed information on FTP and its commands, you can refer to resources like IBM's FTP documentation or Microsoft Learn's networking guides.