FTP: the file transfer protocol
FTP is a standard network protocol for moving files between local and remote file
Copyright By PowCoder代写 加微信 powcoder
user at host
Port number
Port number
IP address
IP address
Local system
Remote system
local file system
remote file system
file transfer
FTP Server
FTP: the file transfer protocol
FTP is a standard network protocol for moving files between local and remote file
user at host
remote file system
directory structures
local file system
The two end-systems may differ in the following aspects: operating systems
file naming conventions
ways of representing text and data
* FTP solved all of these problems using a simple and elegant approach. 3
file transfer
FTP Server
Basic model of FTP
There is an FTP client on one host and an FTP server on another.
user at host
local file system
remote file system
FTP client
file transfer FTP server
user interface
Uses the services of TCP for reliably transferring file to/from remote host
Client/Server model
client: side that initiates transfer (either to/from remote) server: remote host
ftp protocol: RFC 959, RFC 2428 (IPV6 support), RFC 2228 (security)
ftp server: port 21 (control connection), port 20 (data connection)
FTP: the file transfer protocol
The user needs to communicate with an FTP server following the FTP protocol strictly. In aid of this requirement, there is an intermediary FTP user agent that handles the transformation of user’s requests into their corresponding FTP commands.
user at host
remote file system
IP address
IP address
FTP client
file transfer FTP
user agent
Port number
Port number
The operating system provides an FTP user agent (an FTP client) that runs in the command line.
For Assignment #1, We will use this built-in FTP user agent to interact with our FTP
Objectives of FTP From RFC 959 (historic reasons)
user at host
local file system
remote file system
FTP client
file transfer FTP server
user interface
1. promote sharing of files (programs and/or data)
2. encourage indirect or implicit (via programs) use of remote
computers.
3. shield a user from variations in file storage systems among hosts
4. transfer data reliably and efficiently
* FTP was designed mainly for use by programs
Control and Data Connections
Client socket
Connection socket
Client socket
Welcome socket
TCP control connection
TCP data connection
Opened and then closed for each file transfer
(non-persistent).
• FTP sends its control information out-of-band.
Basic Interaction (Active mode)
1. FTP client contacts FTP server at port 21, using TCP
TCP control connection, server port 21
2. client is authenticated over control connection
FTP client
TCP data connection, FTP
3. client browses remote directory by sending commands over control connection.
server port 20
4. when the server receives a file transfer command, it opens a second TCP connection (for file transfer operation) to client
FTP server keeps track of state information about the user (i.e. current directory, earlier authentication)
5. after transferring exactly one file, the server closes the data connection (non-persistent).
Let’s look at a sample FTP server-client interaction…
TWO PARALLEL TCP CONNECTIONS
Listening Socket
TCP Control Socket
PORT 130,123,200,1,195,149 LIST
Sample Active FTP IPv4 Interaction
TCP Control Socket
After a successful authentication, the user types: dir
TCP Active Data Socket
Human user types: quit
After file transfer, server notifies client
The Server should be running already prior to a Client connecting to it
(exchange of messages follows)
Listening Socket
Sample Active FTP IPv4 Interaction
The Server should be running already prior to a Client connecting to it
Listening Socket
authentication, the user
Sample Active FTP IPv6 Interaction
TCP Control Socket
TCP Control Socket
types: dir
EPRT |2|fd94:fe22:9f1d:e700:15b4:b3b0:83ec:7d3f|38117|
The Server should be running already prior to a Client connecting to it
TCP Active Data Socket
After file transfer, server notifies client
After a successful
Human user types: quit
(exchange of messages follows)
RFC 959 RFC 2428
FTP Client-Server Communication
In this example, both Server and Client are running in the same machine.
C:\testFTP>ftp
ftp> open 127.0.0.1 1024
Connected to 127.0.0.1.
<‐‐‐ 220 Service Ready: Awaiting input User (127.0.0.1:(none)): napoleon <‐‐‐ 331 Please send password Password: 342
<‐‐‐ 230 User logged in okay
FTP commands, responses
sample commands:
sample return codes
Commands are sent as four uppercase ASCII characters over control channel
Three-digit status code and optional phrase (as in HTTP)
USER username
PASS password
331 Username OK, password required
LIST return list of file in current directory
125 data connection already open; transfer starting
RETR filename retrieves (gets) file
425 Can’t open data connection
STOR filename stores (puts) file onto remote host
452 Error writing file
Reply codes
Application 2-13
Ephemeral Ports
Control connection
Data connection
Note that Ports 1216 & 1217 are ephemeral ports. Any port [1024, 65535] will work. 16
Source: Computer Networking and the Internet (5/e) by
IPv4 / IPv6
FTP Commands
DESCRIPTION
USER PASS SYST TYPE
username password
User name on the FTP server
Client IP address (n1-n4) and port number (n5, n6)
filename.type
Retrieve (get) a file
Source: Computer Networking and the Internet (5/e) by
type n1,n2,n3,n4,n5,n6
File type to be transferred: A (ASCII), I (Image/Binary)
|AF|net-addr|port|
AF=address family (1 or 2); • 1 for IPv4
User’s password on the FTP server
Find type of operating system at server
• 2 for IPv6
net-addr=IP address in IPv4 or IPv6; port = port number in decimal
FTP Commands
DESCRIPTION
STOR filename.type LIST
Store (put) a file
List files (ls) or directories (dir) Log off from server
Source: Computer Networking and the Internet (5/e) by
FTP Commands
PORT n1,n2,n3,n4,n5,n6
1. ClientIPaddress(n1-n4)
• all decimal numbers
2. portnumber(n5,n6)
• ephemeral port number for the data connection on the client side.
• Each port number is 16 bits long
• n5 is the equivalent of the most significant 8 bits,
• n6 is the least significant 8 bits.
What is the port number represented by n5=195 and n6=149?
See excel file
Source: Computer Networking and the Internet (5/e) by
Second digit First digit
FTP Reply Codes
REPLY DESCRIPTION
1yz Positive preliminary reply, wait for another reply from Server before sending a new command (server sends at most one 1yz reply per command)
2yz Positive completion reply, a new command can be sent
3yz Positive intermediate reply, another command from Client is awaited 4yz Transient Negative reply, try again
5yz Permanent Negative reply, do not retry
x0z Syntax
x1z Information
x2z Control or data connection x3z Authentication
The third digit gives additional information relating to error messages.
x4z Unspecified x5z File status
See RFC959, p.37 20
Source: Computer Networking and the Internet (5/e) by
Sample Replies
125 Data connection already open; transfer starting.
150 File status okay; about to open data connection.
200 Command okay.
202 Command not implemented, superfluous at this site. 211 System status, or system help reply.
215 NAME system type.
Where NAME is an official system name from the list in the Assigned Numbers document.
220 FTP server ready
221 Service closing control connection.
Log out if appropriate.
225 Data connection open; no transfer in progress.
226 Closing data connection.
Requested file action successful (for example, file
transfer or file abort).
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
230 User logged in, proceed.
250 Requested file action okay, completed.
257 "PATHNAME" created.
331 User name okay, need password.
332 Need account for login.
350 Requested file action pending further information.
See RFC959, p.39 21
Sample Replies
421 Service not available, closing control connection.
This may be a reply to any command if the service knows it must shut down.
425 Can't open data connection.
426 Connection closed; transfer aborted.
450 Requested file action not taken.
File unavailable (e.g., file busy).
451 Requested action aborted: local error in processing. 452 Requested action not taken.
Insufficient storage space in system.
500 Syntax error, command unrecognized.
This may include errors such as command line too long. 500 unrecognised command.
501 Syntax error in parameters or arguments.
502 Command not implemented.
503 Bad sequence of commands.
504 Command not implemented for that parameter.
530 User access denied
532 Need account for storing files.
550 Requested action not taken.
File unavailable (e.g., file not found, no access).
551 Requested action aborted: page type unknown.
552 Requested file action aborted.
Exceeded storage allocation (for current directory or dataset).
553 Requested action not taken.
File name not allowed.
See RFC959, p.39 22
p. 59, RFC 959 p. 50, RFC 959
https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes
Data connection
control connection
control connection
Data connection
Source: Computer Networking and the Internet (5/e) by
Passive open
ACTIVE FTP Operation
Data connection
control connection
control connection
Data connection
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
Data connection
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
Data connection
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
Data connection
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
Data connection
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Data connection Active FTP (or Standard ) Data connection Data connection 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
control connection
control connection
Data connection
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
control connection
control connection
Data connection
Port Port 21 1120
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
control connection
control connection
Data connection
Port Port 21 1120
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
control connection
control connection
Data connection
Port Port 21 1120
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
control connection
control connection
Data connection
Port Port 21 1120
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
RETR
control connection
control connection
Data connection
Port Port 21 1120
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
RETR
control connection
control connection
Data connection
Port Port 21 1120
Server does an active open to Port n5, n6
RETR
See RFC959, p.59
TCP control connection to Port 21 established
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
control connection
control connection
Data connection
Port Port 21 1120
TCP control connection to Port 21 established
Server does an active open to Port n5, n6
RETR
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
control connection
control connection
Data connection
TCP control connection to Port 21 established
Server does an active open to Port n5, n6
RETR
User prompted for a command time
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
control connection
control connection
Data connection
Server does an active open to Port n5, n6
RETR
Server closes data connection
TCP control connection to Port 21 established
User prompted for a conmand time
Source: Computer Networking and the Internet (5/e) by
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
control connection
control connection
Data connection
Server does an active open to Port n5, n6
RETR
Server closes data connection
Source: Computer Networking and the Internet (5/e) by
TCP control connection to Port 21 established
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
User prompted for a conmand
control connection
control connection
Data connection
Server does an active open to Port n5, n6
RETR
Server closes data connection
Source: Computer Networking and the Internet (5/e) by
TCP control connection to Port 21 established
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
User prompted for a conmand
control connection
control connection
Data connection
Server does an active open to Port n5, n6
RETR
Server closes data connection Server closes control
User prompted for a conmand
Scoournce:n and the Internet (5/e) by
TCP control connection to Port 21 established
Passive open
Active open
ACTIVE FTP Operation
USER
PASS
get
Sample Interaction (LIST, RETR)
C:\tmp>ftp
ftp> debug
Debugging On .
ftp> open localhost 1234
Connected to IT092024.massey.ac.nz.
220 FTP Server ready
—> OPTS UTF8 ON
550 unrecognised command
User (IT092024.massey.ac.nz:(none)): napoleon
—> USER napoleon
331 Password required
—> PASS 342
230 User logged in okay
—> EPRT |2|::1|56479|
200 EPRT Command okay
150 Data connection opened for file transfer
-rwxrwxrwx 1 napoleon napoleon 3708364 Apr 07 09:44 server.exe 226 Transfer successful, closing data connection
ftp: 70 bytes received in 0.01Seconds 6.36Kbytes/sec.
—> EPRT |2|::1|56486|
200 EPRT Command okay
150 Data connection opened for file transfer
-rw-rw-rw- 1 napoleon napoleon 100376 Feb 18 2019 black.jpg -rwxrwxrwx 1 napoleon napoleon 3708364 Apr 07 09:44 server.exe 226 Transfer successful, closing data connection
ftp: 136 bytes received in 0.02Seconds 6.48Kbytes/sec.
ftp> get black.jpg
—> EPRT |2|::1|56492|
200 EPRT Command okay
—> RETR black.jpg
150 Data connection opened for file transfer
226 Transfer successful, closing data connection
ftp: 100376 bytes received in 0.01Seconds 9125.09Kbytes/sec.
control connection
control connection
Data connection
Source: Computer Networking and the Internet (5/e) by
Passive open
ACTIVE FTP Operation
control connection