Scenario
You need to upload and download files from an FTP server to
support a legacy transfer workflow. You will connect to an FTP
server, authenticate using anonymous login, list available
files, download readme.txt, upload a local
report.log, and then close the session cleanly.
FTP is legacy and typically unencrypted. In production, prefer SFTP/SSH or HTTPS-based transfers when possible. When FTP is unavoidable, validate each transfer and leave an audit trail.
Objective
- Connect to an FTP server from the terminal.
- Authenticate using anonymous login.
- List remote files and confirm availability.
- Download a file and upload a file.
- Exit the FTP client cleanly.
Concepts
- FTP control channel versus data channel behavior during transfers.
- Why FTP is considered insecure (credentials and data can be sent in cleartext).
- Anonymous FTP authentication and common policy constraints.
- Verifying intent before action: list remote contents prior to transfer.
- Transfer validation: confirm completion messages and verify local/remote results.
- Session hygiene: terminate cleanly to avoid hanging sessions and stale state.
Walkthrough
ftp ftp.lpic-server.org
This starts an interactive FTP client session and prompts for a username.
Connected to ftp.lpic-server.org.
220 (vsFTPd 3.0.3)
Name (ftp.lpic-server.org:lab):
anonymous
Anonymous FTP commonly accepts any password depending on server policy. The operational goal is a successful login and a usable transfer mode.
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ls
Validate what is available before transferring. This also confirms you are operating in the expected remote directory.
-rw-r--r-- 1 ftp ftp 1048576 Jan 01 12:00 backup.tar.gz
-rw-r--r-- 1 ftp ftp 20480 Jan 01 12:01 readme.txt
readme.txt to the local machine.
get readme.txt
This pulls the remote file into the current local working directory. Confirm the transfer completes successfully.
local: readme.txt remote: readme.txt
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection.
226 Transfer complete.
report.log.
put report.log
This pushes the local file to the remote server using the same filename unless otherwise specified.
local: report.log remote: report.log
200 PORT command successful.
150 Opening BINARY mode data connection.
226 Transfer complete.
bye
Exiting cleanly closes the control connection and prevents hanging sessions on the server.
221 Goodbye.
Common breakpoints
Confirm DNS resolution and reachability to TCP/21. If the environment blocks FTP, pivot to SFTP/SSH or an approved transfer method.
Not all servers allow anonymous access. Use the correct account credentials or request access through the proper channel.
NAT and firewalls commonly interfere with FTP data connections. If you see repeated data connection failures, switch transfer mode per policy or use a modern protocol.
Confirm you are in the expected remote directory and that you pulled the correct filename. Validate checksums when integrity matters.
Cleanup checklist
This lab is operationally stateful only in terms of files you transferred. Cleanup is verifying what landed locally and what was uploaded remotely, then exiting the client.
ls -l readme.txt report.log
# If still connected:
# bye
You can show a completed download and upload with clear file names, and the FTP session is closed cleanly.
Reference
-
ftp <host>: Starts an interactive FTP client session to the specified server. -
ls: Lists remote directory contents within the FTP session. -
get <remote_file>: Downloads a file from the FTP server to the local machine. -
put <local_file>: Uploads a local file to the FTP server. -
bye: Terminates the FTP session and closes the connection.-
quitis an equivalent command in many FTP clients.
-