Use one of the following options to connect to the server:
|
1
2
3
|
ftp ftp.example.com
ftp 1.2.3.4
ftp user@ftp.example.com
|
You must know the username and password to authenticate with user privileges; otherwise, you can log in as an anonymous user. Let's try to log in to ftp.freebsd.org as anonymous. Open a terminal and execute the following command:
|
1
|
ftp ftp.freebsd.org
|
The session proceeds as follows:
|
1
2
3
4
5
6
7
8
9
10
11
|
Trying 2001:6c8:2:600::132...
Trying 2001:4f8:0:2::e...
Trying 149.20.64.73...
Connected to ftp.freebsd.org.
220 Welcome to freebsd.isc.org.
Name (ftp.freebsd.org:logi.cc): ftp
331 Please specify the password.
Password: ftp
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
|
When you enter your username and password for the ftp.example.com server, you will see the following prompt:
|
1
|
ftp>
|
After that, you can use the ftp server by issuing commands.
Task: View files in a directory
|
1
|
ftp> ls
|
Task: Change directory
|
1
|
ftp> cd DirectoryName
|
Task: Download or copy a file
To copy a single file from a remote ftp server to your local computer, use the get command.
|
1
2
|
get fileName
get fileName newFileName
|
To copy the file README.TXT from ftp.freebsd.org, you need to be in the directory containing this file and execute the command
|
1
|
ftp> get README.TXT
|
Here is the output of this command:
|
1
2
|
ftp> lcd /path/to/new/directory
ftp> lcd /tmp
|
You can find out the current directory using the command:
|
1
|
ftp> lpwd
|
The lpwd command displays the current directory on the local computer. To find out the directory on the remote FTP server, use the pwd command:
|
1
|
ftp> pwd
|
Download multiple files
To download multiple files from a remote FTP server to your local computer at once, use the mget command. Before downloading each file, you will be prompted to confirm the copy operation with Yes/No (Y/N). To avoid this, use the mget command with the -i flag. To download all files, enter:
|
1
|
ftp> mget *
|
To download all files with the .php extension:
|
1
|
ftp> mget *.php
|
Task: Delete a file
To delete a file on a remote FTP server, use the delete command.
|
1
2
|
ftp> delete FileName
ftp> delete output.jpg
|
Task: Upload a single file
To upload only one file to the FTP server, use the put command.
|
1
|
ftp> put FileName
|
For example, let's upload a logo to the FTP server.
|
1
|
ftp> put logo.jpg
|
Task: Upload multiple files
To upload multiple files from your local computer to a remote FTP server at once, use the mput command. You will also need to answer Yes/No (Y/N) to the prompt for each file before uploading. The example below shows uploading all files from the local computer (from the current directory).
|
1
2
|
ftp> mput *
ftp> mput *.php
|
Task: Creating a directory
To create a new directory, use the mkdir command.
|
1
2
3
4
|
ftp> mkdir DirectoryName
ftp>mkdir backup
ftp>cd backup
ftp>pwd
|
Task: Deleting a directory
To delete a directory, use the rmdir command.
|
1
2
3
|
ftp>rmdir DirectoryName
ftp>rmdir images
ftp>ls
|
Task: Choosing the Data Transfer Mode
To transfer files in ASCII mode, enter:
|
1
|
ftp>ascii
|
Note that ASCII mode is the default; it is recommended for transferring text files.
To transfer files in binary mode, enter:
|
1
|
ftp>binary
|
The binary mode is more suitable for images, archives, and so on. In this mode, there is a lower chance of encountering errors during transfer.
Task: Connecting to Another FTP Server
To connect to another FTP server, use the open command:
|
1
|
ftp>open ftp.yandex.ru
|
Thus, we will connect to the FTP server ftp.yandex.ru. You should also know the username and password, but you can also use anonymous login if the server supports it.
Task: Closing an FTP session
Simply enter quit or bye
|
1
|
ftp>quit
|
or
|
1
|
ftp>bye
|
How can I learn more about FTP server commands?
Type ? or help to learn more about FTP commands.
|
1
2
|
ftp>?
ftp>help
|
You can get a brief description of each command:
|
1
2
|
ftp>help CommandName
ftp>help chmod
|
Output:
|
1
|
chmod change file permissions of remote file
|
That's basically it. We have covered the main commands. Now you will be able to handle FTP from the command line without any problems.
