LinuxCommandLibrary

ftp

Transfer files between computers

TLDR

Connect to an FTP server

$ ftp [ftp.example.com]
copy

Connect to an FTP server specifying its IP address and port
$ ftp [ip_address] [port]
copy

Switch to binary transfer mode (graphics, compressed files, etc)
$ binary
copy

Transfer multiple files without prompting for confirmation on every file
$ prompt off
copy

Download multiple files (glob expression)
$ mget [*.png]
copy

Upload multiple files (glob expression)
$ mput [*.zip]
copy

Delete multiple files on the remote server
$ mdelete [*.txt]
copy

Rename a file on the remote server
$ rename [original_filename] [new_filename]
copy

SYNOPSIS

ftp [-v] [-n] [-i] [-d] [-g] [-k] [-x] [-a] [-t] [host]

Once connected to a host, ftp provides its own interactive prompt to issue further commands.

PARAMETERS

-v
    Enables verbose mode, showing all responses from the remote server.

-n
    Prevents auto-login upon initial connection. Users must manually issue the open command.

-i
    Turns off interactive prompting during multiple file transfers (e.g., with mget or mput).

-d
    Enables debugging output, displaying all internal debugging information.

-g
    Disables filename globbing for mget and mput commands, treating wildcards literally.

-k
    Uses Kerberos 4 authentication for connecting to the remote host.

-x
    Uses Kerberos 5 authentication for connecting to the remote host.

-a
    Automatically attempts anonymous FTP login upon connection.

-t
    Enables packet tracing for network debugging.

host
    The hostname or IP address of the remote FTP server to connect to. If not provided, ftp enters interactive mode awaiting an open command.

DESCRIPTION

The ftp command provides a user interface to the File Transfer Protocol (FTP), allowing users to transfer files between a local host and a remote host. It operates in an interactive mode, where users can issue commands to navigate directories, list files, upload, download, and manage file transfer modes (ASCII or binary). While historically a primary method for transferring files, its use has diminished due to inherent security vulnerabilities, such as transmitting passwords and data in plain text. It is still useful for connecting to older FTP servers or for automated scripts where security is less of a concern or handled by other means.

CAVEATS

The primary caveat of using ftp is its inherent lack of security. Passwords and data are transmitted in clear text, making them vulnerable to eavesdropping.
Firewall configurations can sometimes complicate ftp connections, especially when using active mode, requiring specific port ranges to be open on the client side.
For secure file transfers, modern alternatives like sftp (SSH File Transfer Protocol) or scp are strongly recommended over ftp.

INTERACTIVE COMMANDS

Once connected to an FTP server, the ftp program provides a rich set of interactive commands for file operations. Common commands include:
ls: List files on the remote server.
cd: Change directory on the remote server.
lcd: Change directory on the local machine.
get: Download a file from the remote server.
put: Upload a file to the remote server.
mget/mput: Download/upload multiple files.
binary/ascii: Set transfer mode (important for data integrity).
passive: Toggle passive mode, often necessary for traversing firewalls.
quit: Exit the ftp session.

LOGIN AND AUTHENTICATION

When connecting to an FTP server, ftp will prompt for a username and password unless anonymous login is enabled (often by using 'anonymous' as the username and an email address as the password) or specified via options. The ftp command itself does not store credentials; they are entered at the prompt or handled by Kerberos if specified.

HISTORY

FTP (File Transfer Protocol) is one of the oldest and most fundamental network protocols for transferring files, dating back to 1971. Its original specification, RFC 114, was superseded by RFC 959 in 1985, which remains the standard for the protocol today. The ftp client command has been a ubiquitous part of Unix-like operating systems since the early days of the internet. While its fundamental functionality hasn't changed much, its widespread general use has declined significantly due to the rise of more secure protocols like SFTP and HTTPS, which encrypt data and authentication credentials.

SEE ALSO

sftp(1), scp(1), lftp(1), wget(1), curl(1), ftpd(8)

Copied to clipboard