How to use FTP from the command line

This guide is giving examples of how to use the ftp command line tool to:

  1. Connect to a FTP server
  2. Basic of navigations
  3. Upload a file to the FTP server
  4. Download a file from a FTP server
  5. Other tips and tricks

Connect to a server from the CLI

~/$ ftp -i example.com
Connected to example.com.
Name (example.com:mickael):
anonymous
331 Password required for example.com.
Password:
230 User anonymous logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for file list
drwx------ 7 web site 4096 Jun 9 07:12 .
drwx------ 7 web site 4096 Jun 9 07:12 ..
-rw-r--r-- 1 web site 312 Jun 12 2017 .htaccess
drwx------ 3 web site 4096 Jul 5 2020 public
226 Transfer complete.
ftp> cd public
250 CWD command successful.
ftp> pwd
257 "/public" is current directory.

Manage content

Create a local file

ftp> lpwd
Local directory is /home/mickael/
ftp> lcd Documents
Local directory now /home/mickael/Documents
ftp> !ls
/bin/bash
ftp> !touch test.txt
/bin/bash
ftp> !ls
/bin/bash
test.txt

Create / Delete a folder

ftp> mkdir test
257 "/trash" - Directory successfully created
ftp> rmdir test
250 RMD command successful

Upload a file to the FTP server

ftp> put test.txt
---> PORT 192,168,100,33,147,71
200 PORT command successful.
---> STOR test.txt
150 Opening BINARY mode data connection for test.txt
226 Transfer complete

Download a file from the FTP server

ftp> get test.txt
---> TYPE I
200 Type set to I
---> PORT 192,168,100,33,156,59
200 PORT command successful.
---> RETR test.txt
150 Opening BINARY mode data connection for test.txt
226 Transfer complete.

Delete a file

ftp> delete test.txt
---> DELE test.txt 250 DELE command successful.

Other tips and tricks

ftp> quit
~/$


ftp> pwd
Not connected.
ftp> open
Connected to example.com.
Name (example.com:mickael):
anonymous
230 User anonymous logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/" is current directory.