07 Protocols FTP
07 Protocols FTP
JJ
II
J
I
Back
Close
Anonymous FTP
The preferred method of FTP for this course is to use Fetch on the
Macintosh Computers.
• Fetch is a relatively easy to use package
229
• Basically Drag’nDrop or Menu Driven
• See help facility available from Fetch Window Menu for full info.
JJ
II
J
• Also see the online fetch documents (FAQs,...) at I
http://www.fetchsoftworks.com Back
Close
FTP Conventions, File Extensions, ...
• Once connected you browse files/directories, find/select files and
down(up)load
– For Anonymous FTP you are usually be placed in pub
directory (Public Access Directory)).
230
• Most FTP directories have a README.txt file that includes an
index of all the files in the directory.
– Occasionally, README.txt files include information
regarding the compression method used and
– where you can find a free copy of the software needed to
uncompress the file
• File extensions are used to convey information concerning the file
formats
JJ
• Look at the files’ extensions to determine the compression method II
(See section on compression) J
I
Back
Close
How Does FTP Operate
An FTP client and server actually make two connections:
• Control Connection — FTP Protocol Dialogue
• Data Connection — File Transfer
231
JJ
II
J
I
Back
Close
FTP Control Connection
JJ
II
J
I
Back
Close
FTP Standard Control Connection
233
JJ
II
J
I
Back
Close
FTP Alternative Control Connection
234
JJ
II
J
I
Back
Close
Simple FTP Clients
Fetch (and other GUI FTP Clients) easiest to use for general file
transfer
JJ
II
J
I
Back
Close
First We Need a Terminal Window
All the FTP client session commands may be abbreviated to their 239
first three charcters, e.g.
ftp> hel
help or ? [ command-name ] — list of all commands
JJ
II
J
I
Back
Close
Conversing with the Server in the actual FTP Protocol
JJ
II
J
I
Back
Close
File Transfer Type
IMPORTANT: GET THIS RIGHT FOR FILE TYPE:
• (Raw) text files —- ASCII endcoded
• All audio, image, video files — binary encoded
243
• (Almost) All application files (e.g. Word Docs, excel files) — bi-
nary encoded
• all compressed files (e.g. zip, binhex) — binary encoded
• Uuencoded files (.uu) — ASCII endcoded
JJ
II
J
I
Back
Close
Setting the File Transfer Type
You must set file correct file type, Before Transfer:
ascii — transfer of text only files
binary — transfer of files that contain binary data,
244
type [ type-name ] Set the ”representation type” to type-name.
(ascii/binary).
Note: Most GUI FTP clients allow for automatic detection of trans-
fer type
Dont trust them to get this right!!!
JJ
II
J
I
Back
Close
Directory Traversal: Remote (Server) Side
It is useful to know which directory you are currently working in and also change
this if you are not in the right one. You may also wish to make new ones (if you are
allowed)
Traditional UNIX FTP servers allow the ls, dir .... com-
mands to name several files. For example, the command 247
which refers to every file in the current directory whose name ends
with .ps or .ps.gz.
The wild cards can also be used for multiple file downloading and
uploading (which we now go on to discuss).
JJ
II
J
I
Back
Close
Retrieving Files
JJ
II
J
I
Back
Close
Multiple Get
The mget command is typically used with wild cards (see FTP
wild cards above). E.g.
mget *.ps *.ps.gz 249
JJ
II
J
I
Back
Close
The prompt Command
The setting of the prompt is also useful for use with mget (and mput
which we see below)
prompt — Toggle interactive prompting. By default, prompting is
turned on.
250
If prompting is :
Turned on — you have to repsond yes (y) or no (n) to multiple
down/upload request for each file
• sometimes useful — to select files more finely than a wildcard
allows
• can be tedious if wildcard can select all files already
Turned off — any mget or mput will transfer all files, and any JJ
mdelete (see below also) will delete all files. II
J
I
Back
Close
Uploading Files
JJ
II
J
I
Back
Close
Renaming, Deleting Files and Directories
JJ
II
J
I
Back
Close
Terminating the FTP session and Quitting ftp
When have finished all file transfers you will have to:
close /disconnect — Terminate the FTP session with the remote 253
server, and return to the command interpreter.
You could connect (open) to another FTP server, OR
bye/quit — Terminate the FTP session with the remote server and
exit ftp.
JJ
II
J
I
Back
Close
A Complete Example FTP Session
Let us now look at an examle FTP where many of the commands
above are used in practice. We do the following:
• connect to the year1 server — open,
• list the files — dir, 254
Make sure that you can pick out the different ftp commands (ftp>)
and responses in this output (Numbers and followinf text).
Notice that the ftp responses are only displayed when the verbose JJ
feature is turned on – so you may need to do this to see the above for II
yourself. J
I
Back
Close
The FTP Protocol
Like the email protocols SMTP and POP, you enter into a dialog with
a (FTP) server
• Fetch (menu, mouse driven GUI FTP Clients): the Protocol con-
verstaion is taken of for you.
258
• Command line based (UNIX/DOS) ftp clients
– you can turn on debug to see the Protocol command conver-
sation and
– use quote to converse in the protocol yourself
• All protocols are 4 ASCII Characters long
• You connect to FTP Port Numbers 21 (Data) and 20 (Commands)
on the server.
JJ
II
J
I
Back
Close
FTP Protocol Commands
Login on
• The client normally begins each FTP connection with a USER re-
quest;
• then, depending on the server’s response, a PASS request; 259
JJ
II
J
I
Back
Close
The TYPE command — Setting File Transmission Type
• A TYPE request controls the binary flag.
• It requiures a parameter after the command.
There are four possibilities for the parameter:
260
A — Turn the ASCI Text flag on.
(A for Ascii)
A N — Turn the ASCI Text flag off.
(N for non-print, some other flags)
I — Turn the binary flag on.
(I for Image)
L 8 — Turn the binary flag off.
(L for Local Byte Size, can use other numbers (not common)
JJ
Example: type I II
J
• The server accepts the TYPE request with code 200. I
Back
Close
Navigating Directories
• A PWD request asks the server to list the Present Working
Directory.
• A CWD (Change Working Directory) request has a single
parameter giving a pathname for a directory to change to. I
261
• A CDUP request asks the server to remove the last slash,
and everything following it, from the name prefix.
If this produces an empty name prefix, the new name prefix is a
single slash.
JJ
II
J
I
Back
Close
Listing Files: The LIST and NLST commands
A LIST or NLST request asks the server to send the contents of the
Current Working Directory over the data connection already 262
established by the client.
JJ
II
J
I
Back
Close
Connecting to new Server: PASV and PORT Commands
JJ
II
J
I
Back
Close
Retrieving Files: RETR and REST Commands
• A RETR request asks the server to send the contents of a file over
the data connection already established by the client.
• The REST N command — Restart download 264
The server keeps track of a start position for the client.
– The start position is a nonnegative integer (N).
– At the beginning of the FTP connection, the start position is
clearly 0.
– Most Modern FTP clients can use this feature.
– Useful for restarting partial downloads
JJ
II
J
I
Back
Close
Uploading/Storing files
• A STOR request asks the server to read the contents of a file from
the data connection already established by the client.
• APPE is just like STOR except that, if the file already exists, the
server appends the client’s data to the file.
265
• STOU is just like STOR except that it asks the server to create a file
under a new pathname selected by the server.
JJ
II
J
I
Back
Close
Directory Commands and Deleting Files
• A MKD pathname request asks the server to create a new
directory.
The MKD parameter pathname specifies the directory name.
• An RMD pathname request asks the server to remove a directory. 266
• A DELE filename request asks the server to remove a regular
file.
• A RNFR filename1 request asks the server to begin renaming
a file.
• A RNTO filename2 request asks the server to finish renaming
a file. must immediately follow RNFR filename1.
– Together the rename filename1 to filename2
JJ
II
J
I
Back
Close
The HELP command
JJ
II
J
I
Back
Close
The Example FTP Session with Protocols
ftp> debug
Debugging on (debug=1).
ftp> open ftp.cs.cf.ac.uk
Connected to thrall.cs.cf.ac.uk.
220-************************************************************************
220- Cardiff Computer Science campus ftp access. Access is available
220- here as anonymous, by ftp group or by username/password.
220-
220- The programs and data held on this system are the property of the
220- Department of Computer Science in the University of Wales, Cardiff.
269
220- They are lawfully available to authorised Departmental users only.
220- Access to any data or program must be authorised by the Department
220- of Computer Science.
220-
220- It is a criminal offence to secure unauthorised access to any programs
220- or data on this computer system or to make any unauthorised
220- modification to its contents.
220-
220- Offenders are liable to criminal prosecution. If you are not an
220- authorised user do not log in.
220-************************************************************************
220-
220-Cardiff University. Department of Computer Science.
220-This is the WUSL ftp daemon. Please report problems to
[email protected].
220-
220 thrall.cs.cf.ac.uk FTP server (Version wu-2.6.1(1) Mon Sep 18 12:45:30 BST 2000) ready. JJ
Name (ftp.cs.cf.ac.uk:dave): year1
---> USER year1 II
331 Password required for year1.
Password: J
---> PASS year1ic
230- I
230-Welcome to the guest ftp server for Year 1 Internet Computing
Back
Close
230-in the Department of Computer Science at the University of Wales, Cardiff.
230-
230-Please note that all commands and transfers from this ftp account
230-are logged and kept in an audit file.
230-
230-
230 User year1 logged in. Access restrictions apply.
ftp> dir
---> PORT 131,251,42,151,155,230
200 PORT command successful.
---> LIST
150 Opening ASCII mode data connection for /bin/ls. 270
total 32
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_gif
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_hqx
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_text
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_uu
drwxrwxrwx 2 y1ftp 2048 Nov 8 1999 ex_zip
drwxr-xr-x 2 y1ftp 512 Oct 18 1999 exercise
drwxrwxr-x 2 gueftp 2048 Nov 5 1999 incoming
drwx--x--x 2 staff 1024 Nov 11 1999 marker
drwxrwxr-x 2 gueftp 2048 Nov 10 1999 test
226 Transfer complete.
489 bytes received in 0.0064 seconds (75.12 Kbytes/s)
ftp> cd exercise
---> CWD exercise
250 CWD command successful.
ftp> dir
---> PORT 131,251,42,151,155,231
200 PORT command successful.
JJ
---> LIST II
150 Opening ASCII mode data connection for /bin/ls.
total 156 J
-rw-rw-r-- 1 staff 25943 Dec 8 1997 ex.gif
-rw-rw-r-- 1 staff 53104 Oct 18 1999 ex.txt I
226 Transfer complete.
Back
Close
117 bytes received in 0.0022 seconds (52.60 Kbytes/s)
ftp> bin
---> TYPE I
200 Type set to I.
ftp> get ex.gif
---> PORT 131,251,42,151,155,232
200 PORT command successful.
---> RETR ex.gif
150 Opening BINARY mode data connection for ex.gif (25943 bytes).
226 Transfer complete.
local: ex.gif remote: ex.gif
25943 bytes received in 0.092 seconds (275.08 Kbytes/s) 271
ftp> prompt
Interactive mode off.
ftp> prompt
Interactive mode on.
ftp> mget *.*
---> PORT 131,251,42,151,155,233
---> TYPE A
---> NLST *.*
---> TYPE I
mget ex.gif? y
---> PORT 131,251,42,151,155,234
200 PORT command successful.
---> RETR ex.gif
150 Opening BINARY mode data connection for ex.gif (25943 bytes).
226 Transfer complete.
local: ex.gif remote: ex.gif
25943 bytes received in 0.1 seconds (252.73 Kbytes/s)
mget ex.txt? y
JJ
---> PORT 131,251,42,151,155,235 II
200 PORT command successful.
---> RETR ex.txt J
150 Opening BINARY mode data connection for ex.txt (53104 bytes).
226 Transfer complete. I
local: ex.txt remote: ex.txt
Back
Close
53104 bytes received in 0.17 seconds (297.91 Kbytes/s)
ftp> close
---> QUIT
221-You have transferred 104990 bytes in 3 files.
221-Total traffic for this session was 107294 bytes in 6 transfers.
221-Thank you for using the FTP service on thrall.cs.cf.ac.uk.
221 Goodbye.
ftp>
272
Make sure that you can pick out the different ftp PROTOCOL
commands and responses and see how they relate to the ftp client
commands in this output.
JJ
II
J
I
Back
Close
FTP Etiquette
• Not every site which supports FTP allows anonymous transfers
• Don’t pester FTP administrators with any questions you might
have. They are under no obligation to support you
• Normally, you should limit your accesses to non-business hours 273
(FTP site local time)
• This is especially true when accessing sites on another continent
• Don’t transfer files indiscriminantly
• Have some idea what you’re transferring and think through your
need to have such files
• If you find some files which may be of interest to others at your
own site, publicize it and try to make it available
JJ
II
J
I
Back
Close
Secure FTP (SFTP)
Why Do I need SFTP
• If you wish to access our School’s Computers from outside of
School
– If you upload files to your account 274
JJ
II
J
I
Back
Close