FTP protocolli reti comandi trasferimento-file

Basic FTP Commands

FTP (File Transfer Protocol) is a standard network protocol for transferring files between a client and a server. It follows the client-server model and uses two separate TCP connections: one for commands (port 21) and one for data (port 20 in active mode).

Starting the FTP client

ftp                          # Opens the interactive FTP client
ftp hostname                 # Opens the client and connects directly
ftp 192.168.1.10             # Connect via IP address

Connection commands

CommandDescription
open <host>Opens a connection to the specified server
user <username>Specifies the username for authentication
pass <password>Specifies the password (not recommended in plaintext)
bye / quitCloses the connection and exits the FTP client
closeCloses the server connection but keeps the client open
disconnectSynonym for close
ftp> open ftp.example.com
Connected to ftp.example.com.
Name (ftp.example.com:user): mario
Password: ****
230 Login successful.

Remote and local navigation

CommandDescription
ls / dirLists files in the current remote directory
ls -laDetailed listing (including hidden files)
cd <dir>Changes the remote directory
cd ..Moves up one level in the remote directory tree
pwdShows the current remote directory
mkdir <dir>Creates a directory on the remote server
rmdir <dir>Removes a directory on the remote server
delete <file>Deletes a file on the remote server
rename <old> <new>Renames a file on the remote server
lcd <dir>Changes the local directory (on your PC)
!pwdShows the current local directory

Download (server → client)

CommandDescription
get <file>Downloads a single file from the server
get <file> <local_name>Downloads and renames the file locally
mget <pattern>Downloads multiple files (e.g. mget *.txt)
recv <file>Synonym for get
ftp> get document.pdf
ftp> get report.docx draft_report.docx
ftp> mget *.jpg

With mget the client asks for confirmation for each file. To disable confirmation: prompt off


Upload (client → server)

CommandDescription
put <file>Uploads a single file to the server
put <file> <remote_name>Uploads and renames the file on the server
mput <pattern>Uploads multiple files (e.g. mput *.csv)
send <file>Synonym for put
append <file>Appends the local file to the end of a remote file
ftp> put report.pdf
ftp> put draft.txt final.txt
ftp> mput *.log

Transfer modes

FTP supports two transfer modes that must be selected correctly before uploading or downloading files.

CommandModeUse
asciiASCII textText files (.txt, .csv, .html)
binaryBinary (raw)Any other file (.pdf, .zip, .jpg, .exe)
ftp> ascii
200 Switching to ASCII mode.
ftp> get readme.txt

ftp> binary
200 Switching to Binary mode.
ftp> get archive.zip

Warning: transferring binary files in ASCII mode corrupts them. Always use binary when in doubt.


Session management

CommandDescription
promptToggles interactive confirmation for mget/mput
prompt offDisables confirmations (transfers everything without asking)
statusShows connection status and current settings
hashToggles display of # characters during transfer
verboseToggles display of server messages
help / ?Shows the list of available commands
help <command>Shows help for a specific command

Running local commands

Any command prefixed with ! is executed on the local machine without leaving FTP:

ftp> !ls                   # list local files
ftp> !pwd                  # current local directory
ftp> !mkdir new_folder     # create local folder
ftp> !cat file.txt         # display local file content

Complete session example

$ ftp ftp.example.com
Connected to ftp.example.com.
Name: mario
Password:
230 Login successful.

ftp> ls
200 PORT command successful.
226 Directory send OK.
archive/   documents/   readme.txt

ftp> cd documents
250 Directory successfully changed.

ftp> binary
200 Switching to Binary mode.

ftp> get report.pdf
226 Transfer complete.

ftp> lcd /home/mario/upload
ftp> put project.zip
226 Transfer complete.

ftp> mget *.csv
prompt off
ftp> mget *.csv
226 Transfer complete.

ftp> bye
221 Goodbye.

Essential commands summary

CategoryCommands
Connectionopen, user, bye, close
Remote navigationls, dir, cd, pwd, mkdir
Local navigationlcd, !pwd, !ls
Downloadget, mget
Uploadput, mput
Transfer modeascii, binary
Utilitiesprompt, hash, status, help

Security notes

FTP transmits credentials and data in plaintext on the network. For production environments, prefer:

  • SFTP (SSH File Transfer Protocol) — secure transfer over SSH, port 22
  • FTPS (FTP over SSL/TLS) — encrypted FTP, port 990 (implicit) or 21 (explicit)
  • SCP (Secure Copy) — secure copy over SSH