ftp - Linux
Overview
The ftp
command stands for File Transfer Protocol. It is used to transfer files between computers on a network. FTP is a client-server protocol that allows a user on one computer to transfer files to and from another computer over a TCP/IP network. This command is particularly useful for uploading files to a web server or for downloading software and data from remote servers.
Syntax
The basic syntax of the ftp
command is:
ftp [options] [hostname]
- hostname: This is an optional argument where you can specify the address of the FTP server you want to connect to directly.
Usage Variations:
-
To start ftp in interactive mode without a predetermined server:
ftp
-
To connect directly to an FTP server:
ftp example.com
-
To transfer files using specific credentials:
ftp -u user:password@hostname
Options/Flags
-
-v: Suppresses verbose output. Without this flag, ftp will run in verbose mode by default, showing all the responses from the FTP server and indicating all the files being transferred.
-
-i: Turns off interactive prompting during multiple file transfers.
-
-d: Enables debugging mode. Displays debugging information detailing the commands passed between the FTP client and FTP server.
-
-p: Enables “passive” mode which is useful when the client is behind a firewall and unable to accept incoming TCP connections.
-
-u: Specifies the user and password for login using the format
user:password
.
Examples
-
Basic FTP session:
ftp example.com
-
Downloading a file:
ftp open example.com get filename.txt quit
-
Uploading a file in passive mode:
ftp -p example.com put localfile.txt quit
-
Using interactive mode to transfer multiple files:
ftp -i example.com mget *.png mput *.txt quit
Common Issues
-
Connection Refused: This error occurs if the FTP server is not running on the server or the server is unreachable. Check server status and ensure that your network connection is active.
-
Login failure: Often due to incorrect username or password. Verify credentials and try again.
-
Passive Mode Errors: When having trouble with passive mode operations, ensure that firewalls are configured correctly.
Integration
ftp
can be integrated with shell scripts to automate uploading and downloading tasks.
Example Script for Automated Backup via FTP:
#!/bin/bash
HOST='ftp.example.com'
USER='yourusername'
PASSWD='yourpassword'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /path/to/remote/backup
put /path/to/local/backup.tar.gz
quit
END_SCRIPT
exit 0
Related Commands
sftp
: Secure File Transfer Protocol. Uses SSH to encrypt the data transferred.scp
: Secure Copy Protocol. Used for copying files over SSH.curl
: Command-line tool for transferring data using various protocols including FTP, FTPS, HTTP, HTTPS.
For further reading and more detailed information about the ftp
command, you can access the FTP manual by typing man ftp
in your command line, or visit the GNU FTP manual online.