1
File Transfer
Protocol
(FTP)
2
CONTENTS
CONNECTIONS
COMMUNICATION
COMMAND PROCESSING
FILE TRANSFER
SIMPLE FTP -- Assignment
3
File Transfer Protocols (FTP)
Transferring files from one computer to another
Using two connections between hosts
One for data transfer
One for control information
Three components for clients,user interface,
client control process,and client data transfer
process
Two components for servers,server control
process and server data transfer process
4
FTP uses the services of TCP,
It needs two TCP connections,
The well-known port 21 is used
for the control connection
and the well-known
port 20 for the data connection.
5
Figure 20-1
The control connection remains connected during
the entire interactive FTP session; the data connection
is opened and then closed for each file transferred.
6
CONNECTIONS
7
Connections – Control Connection
Created in the same ways as other applications
Server issues a passive open on port 21 and waits
Clients uses an ephemeral port and issues an active
open
Remains open during the entire process
Needs minimize delay for service
8
Figure 20-2
9
Connection – Data Connection
Uses the port 20 usually at the server side
Creation of a data connection includes
Client issues a passive open using an ephemeral port
Client sends this port number to the server using
PORT command
Server receives the port number and issues an active
open using the well-known port
Figure 20-3
11
COMMUNICATION
12
Communication
FTP client and server run on different
computers using different OS,character sets,
and file formats.
FTP must take this heterogeneity compatible
Communication over
Control connection
Data connection
13
Communication over Control
Connection
Uses the NVT ASCII character set
Achieves the communication by commands
and responses
Each command or response is a short line
terminated with a two-character (CR+LF) end-
of-line token
14
Figure 19-3
NVT
15
Figure 20-4
Using the control connection
16
Communication over Data
Connection
Transfer files through the data connection
The client must define
File type
Data structure
Transmission mode
Before sending the file through the data
connection,we prepare for transmission
through control connection
17
File Type
ASCII file
default format for transferring text file
EBCDIC file
Image file
default format for transferring binary files
Mostly used to transfer binary files such as compiled
programs
Nonprint v.s,TELNET attribute
18
Data Structure
File structure (default)
Continuous stream of bytes
Record structure
Divided into records (or structs in C)
Used only with text files
Page structure
Divided into pages each having a page number and
header
Can be stored or accessed randomly or sequentially
19
Transmission Mode
Stream mode
Default mode
Data are delivered from FTP tp TCP as a continuous
stream of bytes
Block mode
Compressed Mode
20
Figure 20-5
Using the data connection
21
COMMAND
PROCESSING
22
Command Processing
FTP uses the control connection to
communication.
Commands are sent from the client to the
server and the responses are sent back from the
server to the client.
23
Figure 20-6
Command processing
24
Commands
In the form of ASCII uppercase
May be followed by an argument
Six groups:
Access commands
File management commands
Data format commands
Port defining commands
File transferring commands
Miscellaneous commands
25
Access Commands
include
USER user-id
PASS user-passwd
ACCT account to be changed
REIN
QUIT
ABOR
26
File Management Commands
includes
CWD dir
CDUP
DELE file
LIST dir
NLIST dir
MKD dir
PWD
RMD dir
27
Data Formatting Commands
includes
TYPE A(ASCII),E(EBCDIC),I (Image),N
(Nonprint),or T(TELNET)
STRU F (File),R (Record),or P (page)
MODE S (Stream),B (Block),or C (Compressed)
28
Port Defining Commands
Define the port number for the data connection
on the client site
Selects an port number and sends it to the server
using a passive open
Asks the server to choose a port number and send
the port number in the response and then the client
creates an active open using that port
Two commands
PORT (6-digits id)
PASV
29
File Transfer Commands
include
RETR file(s)
STOR file(s)
APPE file(s)
STOU file(s)
ALLO file(s)
REST file(s)
STAT file(s)
30
Miscellaneous Commands
include
HELP
NOOP
SITE
SYST
31
Responses
Each FTP command generates at least one
response
Each response has two parts:
3-digit number,defines the code
Text,defined needed parameters or extra
explanations
32
FILE
TRANSFER
33
File Transfer
One of the three things
Retrieving a file (RETR)
Storing a file (STOR)
Listing directory or file names (LIST)
Note that,FTP treats a list of directory or file name
as a file and sends it over the data connection.
34
Figure 20-7
File transfer
35
Example of Retrieving a list
36
Example of storing an image
(binary) file
37
USER
INTERFACE
38
%ftp challenger.atc.fhda.edu
Connected to challenger.atc.fhda.edu
220 Server ready
Name,forouzan
Password,xxxxxxx
ftp > ls /usr/user/report
200 OK
39
150 Opening ASCII mode
...........
226 transfer complete
ftp > close
221 Goodbye
ftp > quit
40
Homework 3 Simple FTP
Implement a simple FTP client
Start your ftp service on the client side by
typing sftp
To connect to a server,use open command
open hostname (or IP)
Exit the service by giving the bye command
41
Commands to be Implemented
Two categories for the other commands
Commands on the remote machine
ls,cd,get,mget,put,mput
Commands on the local machine
lls,lcd
20 points bonus for implementing recursive
downloading files by
get –R directory
42
Outline
Overview
General Commands
Login & Logout Scenario
Some Details
FTP Tool—Debug Mode
Conclusion
43
Overview
44
General Commands
USER id
PASS password
PORT h1,h2,h3,h4,p1,p2
PORT 140,124,181,110,4,200
IP:140.124.181.110
Port:4*256+200=1224
TYPE mode
A?ASCII
I?Binary
45
General Commands
LIST
RETR path
download
STOR path
upload
QUIT
PASS
Return h1,h2,h3,h4,p1,p4
46
Login & Logout Scenario
47
Some Details
48
Conclusions
lls & lcd commands requirement,system
programming
open,quit,and a command of server are
required
Email title:hw3_sftp
Files,compress and tar your files