File Transfer Protocols: FTP and TFTP
Overview
- Concept: Industry-standard protocols used to transfer files over a network using a client-server model.
- Primary Use Case: Upgrading the Cisco IOS image on network devices (downloading from a server to the device’s flash memory).
- Exam Topic: 4.9 (Describe the capabilities and function of TFTP and FTP in the network).
Trivial File Transfer Protocol (TFTP)
- Concept: A simple, lightweight protocol standardized in 1981, designed for quick transfers of small files in controlled environments.
- Transport: Uses UDP port 69.
- Security: None. No authentication (no usernames/passwords) and no encryption (data sent in plain text).
- Functionality: Limited strictly to copying files to or from a server. Cannot list, delete, or navigate directories.
- Reliability: UDP is connectionless, but TFTP implements its own basic reliability using ACKs and retransmissions (lock-step communication).
- Every data message must be acknowledged.
- Timers trigger retransmissions if an expected message is not received.
- Connection Phases:
- Connection: Client sends a read/write request; server responds with the first data packet.
- Data Transfer: Exchange of data packets and ACKs.
- Termination: Final ACK is sent after the last data packet.
- Port Behavior (Transfer Identifier - TID):
- Client sends initial request from a random ephemeral port (TID) to UDP port 69.
- Server replies using a random TID as its source port (NOT port 69).
- Subsequent communication uses these two random ports. Port 69 is only used for the very first message from the client.
File Transfer Protocol (FTP)
- Concept: A complex, feature-rich protocol standardized in 1971 (predating TCP/IP).
- Transport: Uses TCP ports 20 and 21.
- Security: Uses usernames and passwords for authentication (sent in plain text).
- FTPS: FTP over SSL/TLS (adds encryption to FTP).
- SFTP: SSH File Transfer Protocol (a completely different protocol that uses SSH, not an upgrade to FTP).
- Functionality: Allows file transfers, directory navigation, listing files, and creating/deleting directories.
- Dual Connection Architecture:
- Control Connection (TCP Port 21): Used for sending FTP commands and receiving server replies. Established first and maintained throughout the session.
- Data Connection (TCP Port 20): Used for the actual file/data transfer. Established and terminated dynamically as needed.
- Data Connection Modes:
- Active Mode (Default): The server initiates the TCP data connection to the client.
- Passive Mode: The client initiates the TCP data connection to the server. Crucial when the client is behind a firewall that blocks incoming connections from the outside.
FTP vs TFTP Comparison
| Feature | FTP | TFTP |
|---|---|---|
| Transport Protocol | TCP (Connection-oriented) | UDP (Connectionless) |
| Port(s) | TCP 20 (Data), TCP 21 (Control) | UDP 69 |
| Authentication | Yes (Username/Password) | No |
| Encryption | No (Plain text) | No (Plain text) |
| Functionality | Advanced (List, delete, navigate directories) | Basic (Copy files only) |
| Reliability | Handled by TCP | Handled internally (ACKs/Retransmissions) |
| Use Case | General file transfer, internet | Quick, small file transfers in controlled LANs |
Cisco IOS File Systems
- Concept: Cisco IOS uses various file systems to store and retrieve data. Viewed using
show file systems. - File System Types:
- disk: Physical storage devices like flash memory (stores the IOS image).
- nvram: Non-Volatile RAM (stores the startup-config). Retains data without power.
- opaque disk: Logical internal systems for specific internal functions.
- network: Represents external file systems (e.g., FTP or TFTP servers).
IOS Upgrade Process (CLI Commands)
- Concept: The standard workflow for upgrading a Cisco device’s IOS using a TFTP or FTP server.
- Step 1: Verify Current State
Router# show version
Router# show flash
- Step 2: Configure FTP Credentials (If using FTP)
Router(config)# ip ftp username cisco
Router(config)# ip ftp password cisco
- Step 3: Copy IOS Image to Flash
Router# copy tftp: flash:
! Prompts for: Server IP, Source Filename, Destination Filename
Router# copy ftp: flash:
! Prompts for: Server IP, Source Filename, Destination Filename
- Step 4: Configure Boot Variable
Router(config)# boot system flash:<new_ios_filename.bin>
Things to note: If the boot system command is not configured, the router will automatically boot the first IOS file it finds in flash memory.
- Step 5: Save and Reload
Router(config)# end
Router# copy running-config startup-config
Router# reload
- Step 6: Clean Up (Delete Old IOS)
Router# delete flash:<old_ios_filename.bin>
Summary of Commands
! View file systems
Router# show file systems
! Verify current IOS and flash contents
Router# show version
Router# show flash
! Configure FTP credentials (Global Config)
Router(config)# ip ftp username <username>
Router(config)# ip ftp password <password>
! Copy file from TFTP/FTP server to Flash
Router# copy tftp: flash:
Router# copy ftp: flash:
! Set the boot variable (Global Config)
Router(config)# boot system flash:<filename>
! Save configuration
Router# copy running-config startup-config
! Reboot the device
Router# reload
! Delete a file from flash
Router# delete flash:<filename>