FTP Assignment
FTP Assignment
Assignment
Submitted to:-
Submitted by:-
Date:-
11-May-10
FTP is designed mainly for use by programs though it is usable directly by a user at a
terminal.At the broadest level, FTP access to a particular machine can be
disabled;however, this excludes advantageous use of FTP as well as unwanted
usage.Because of this machines that support FTP provide file and directory accesscontrol.
Hence, a user can retain full access to their files, permit group members to read(but not
write/delete) their files, and deny access to all other people.Access control is normally
accomplished by associating a number of access flags with eachfile and directory (e.g. a
read-only flag, etc.). How this is done is OS specific, however, the most commonly
encountered using FTP is UNIX based and is shown below:
Three groups of access flags are provided: for the user, their workgroup and then general
access. Three flags are included within each group: one for read access, another for write
access, and third for executes privileges.
Functionality of FTP
TCP is a client-server process, whereby an FTP server (a daemon listening for incoming
FTP requests/commands) interacts with FTP clients.
In essence, FTP provides a means of transferring a file between two computers,
however, most FTP clients also permit the user to navigate the file system, create/delete
directories/files (if permitted) on both the local and connected machines.
A number of more recent FTP clients also offer repeated download attempts, re-
connection should the connection be lost, resumed downloads.
FTP was first proposed in 1971, with the current standard (introduced in 1985) defined
with international document RFC959.
The FTP client consists of a User Protocol Interpreter (PI) that initiates a connection with
the Server Protocol Interpreter (using port 21). The user PI sends FTP commands to the
server PI, which in turn replies back to the user PI.
The user and server data transfer processes (operating on port 20) are used to transfer
data between the client and server. Note, the connection is duplex, and is only established
whenever some data needs to be sent (the connection is relinquished whenever the data
transfer has completed). The FTP client will also contain a user interface, permitting the
user to specify which FTP commands are to be sent by the user PI to the server PI.
ASCII/Text only: This is the default FTP format, and stipulates that all data
isencoded as 8-bit ASCII.
Binary/Image: Data is encoded as contiguous 8-bit bytes.
ASCII and binary formats differ in that if the data is classified as ASCII then certain
bytes will be interpreted as end-of-line markers, etc.
By default, FTP sessions are established on port 21, although the server may be
configured to accept connections on a different port.
It is the server’s responsibility to initate the data connection, to maintain it and to
close it. Furthermore, all data transfers must be accomplished with an end-of-file
(EOF), which may be explicitly send, or implied if the data connection is closed.
FTP servers normally have a timeout period, usually a few minutes. The timeout
period is reset each time the client sends a command. The client is disconnected if
the timeout expires.
FTP Commands
The following list of commands are those employed within the User and Server Protocol
Interpreters (PIs). Typically the PI commands are more primitive than the commands that
the user interface offers, i.e. FTP clients provide a simplified interface. However, the user
can directly issue FTP commands if so desired.
• USER – User name: This command is normally the first one sent to the server after the
control connection has been made, and is used to identify the user to the server, and
hence the degree of file access they command. The username is passed as the argument.
• PASS – Password: This command must be sent immediately after the user name
command and for most sites completes the user’s identification. It is the responsibility of
the FTP client to ensure that sensitive password information is protected (i.e. not echoed
to the screen, etc.). The password is passed as the argument.
• CWD – Change Working Directory: This command permits the user to change to a
different directory for file storage and retrieval, assuming sufficient access privileges.
The desired working directory is passed as the argument.
• REIN – Reinitialise: This command terminates the user’s connection, allowing the
current file transfer, if any, to complete. All parameters are then reset to the default
setting, i.e. equivalent to the state the user finds themselves in upon first connection.
• QUIT – Logout: This command terminates the user’s connection, with the server
closing any file transfers currently in progress.
• PORT – Data Port: This command permits the port used for data transfer to be
specified. The command accepts as arguments a 32-bit internet host address, and a 16-bit
port address.
• RETR – Retrieve: This command causes the server data transfer process (DTP) to
transfer a copy of the specified file to the user DTP (assuming the user has sufficient
access privileges).
• STOR – Store: This command causes the server DTP to accept the data transferred
from the user DTP and to store the data server side (assuming the user has sufficient
access privileges).
• STOU – Store Unique: This command is the same as STOR, except that the file to be
stored by the server must be generated using a name that is unique to the directory within
which it is to be stored. The server’s reply must include the name of the created file.
• APPE – Append: This command causes the server to accept data from the client, and
store it in the specified file, appending it to the end of the file if it already exists.
• RNFR – Rename From: This command specifies the name of a file that is to be
remained. It is used in conjunction with RNTO.
• RNTO – Rename To: This command takes the file identified by the RNFR command
and assignes it the new specified filename (provided the user has sufficient access
privileges).
• ABOR – Abort: This command tells the server to abort the previous FTP command and
any associated data transfer.
• DELE – Delete: This command causes the specified file to be deleted on the server
(assuming the user has sufficient access privileges).
• MKD – Make Directory: This command causes the directory specified as the argument
to be created (assuming the user has sufficient access privileges).
• PWD – Print Working Directory: This command causes the name of the current
working directory to be returned.
• LIST – List: This command causes a list of all the files and directories within the
current working directory to be sent to the client.
• HELP – Help: This command results in the server sending helpful information
regarding its implementation, etc.
• NOOP – No Operation: This command specifies that the server sends an OK reply –
most often used to keep the FTP connection ‘alive’.
FTP Replies
The FTP server sends replies back to the FTP client, providing information about the last
command. Replies assume the following format:
The three digit number uniquely identifies the reply returned by the FTP server (and the
FTP client bases its response upon the received digits), i.e. it is intended that the three
digit number contain sufficient encoded information that the user PI need not examine the
appended text. The number is normally followed by some useful textual information,
which is intended for the user.
From time-to-time it will be necessary for the server to send a multi-line response. The
FTP protocol specifies that this is accomplished by immediately following the 3 digit
code by a hyphen, and then signifying the end of the multi-line message by sending the
same three digit code again,
this time followed by a space, e.g.
Types of FTP
From a networking perspective, the two main types of FTP are active and passive.
In active FTP, the FTP server initiates a data transfer connection back to the client. For
passive FTP, the connection is initiated from the FTP client.
From a user management perspective there are also two types of FTP: regular FTP in
which files are transferred using the username and password of a regular user FTP server,
and anonymous FTP in which general access is provided to the FTP server using a well
known universal login method.
Active FTP
The sequence of events for active FTP is:
1. Your client connects to the FTP server by establishing an FTP control connection
to port 21 of the server. Your commands such as 'ls' and 'get' are sent over this
connection.
2. Whenever the client requests data over the control connection, the server initiates
data transfer connections back to the client. The source port of these data transfer
connections is always port 20 on the server, and the destination port is a high port
(greater than 1024) on the client.
3. Thus the ls listing that you asked for comes back over the port 20 to high port
connection, not the port 21 control connection.
FTP active mode therefore transfers data in a counter intuitive way to the TCP standard,
as it selects port 20 as it's source port (not a random high port that's greater than 1024)
and connects back to the client on a random high port that has been pre-negotiated on the
port 21 control connection.
Active FTP may fail in cases where the client is protected from the Internet via many to
one NAT (masquerading). This is because the firewall will not know which of the many
servers behind it should receive the return connection.
Passive FTP
Passive FTP works differently:
1. Your client connects to the FTP server by establishing an FTP control connection
to port 21 of the server. Your commands such as ls and get are sent over that
connection.
2. Whenever the client requests data over the control connection, the client initiates
the data transfer connections to the server. The source port of these data transfer
connections is always a high port on the client with a destination port of a high
port on the server.
Passive FTP should be viewed as the server never making an active attempt to connect to
the client for FTP data transfers. Because client always initiates the required connections,
passive FTP works better for clients protected by a firewall.
As Windows defaults to active FTP, and Linux defaults to passive, you'll probably have
to accommodate both forms when deciding upon a security policy for your FTP server.
Regular FTP
By default, the VSFTPD package allows regular Linux users to copy files to and from
their home directories with an FTP client using their Linux usernames and passwords as
their login credentials.
VSFTPD also has the option of allowing this type of access to only a group of Linux
users, enabling you to restrict the addition of new files to your system to authorized
personnel.
The disadvantage of regular FTP is that it isn't suitable for general download distribution
of software as everyone either has to get a unique Linux user account or has to use a
shared username and password. Anonymous FTP allows you to avoid this difficulty.
Anonymous FTP
Anonymous FTP is the choice of Web sites that need to exchange files with numerous
unknown remote users. Common uses include downloading software updates and MP3s
and uploading diagnostic information for a technical support engineers' attention. Unlike
regular FTP where you login with a preconfigured Linux username and password,
anonymous FTP requires only a username of anonymous and your email address for the
password. Once logged in to a VSFTPD server, you automatically have access to only the
default anonymous FTP directory (/var/ftp in the case of VSFTPD) and all its
subdirectories.
With Redhat / Fedora you can configure VSFTPD to start at boot you can use the
chkconfig command.
With Ubuntu / Debian the sysv-rc-conf command can be used like this:
root@u-bigboy:/tmp# sysv-rc-conf on
Note: In RedHat Linux version 8.0 and earlier, VSFTPD operation is controlled by the
xinetd process, which is covered in Chapter 16, "Telnet, TFTP, and xinetd". You can find
a full description of how to configure these versions of Linux for VSFTPD in Appendix
III, "Fedora Version Differences."
This file uses a number of default settings you need to know about.
• VSFTPD runs as an anonymous FTP server. Unless you want any remote user to
log into to your default FTP directory using a username of anonymous and a
password that's the same as their email address, I would suggest turning this off.
The configuration file's anonymous_enable directive can be set to no to disable
this feature. You'll also need to simultaneously enable local users to be able to log
in by removing the comment symbol (#) before the local_enable instruction.
• If you enable anonymous FTP with VSFTPD, remember to define the root
directory that visitors will visit. This is done with the anon_root directive.
anon_root=/data/directory
• VSFTPD allows only anonymous FTP downloads to remote users, not uploads
from them. This can be changed by modifying the anon_upload_enable directive
shown later.
• VSFTPD doesn't allow anonymous users to create directories on your FTP server.
You can change this by modifying the anon_mkdir_write_enable directive.
• VSFTPD logs FTP access to the /var/log/vsftpd.log log file. You can change this
by modifying the xferlog_file directive.
• By default VSFTPD expects files for anonymous FTP to be placed in the /var/ftp
directory. You can change this by modifying the anon_root directive. There is
always the risk with anonymous FTP that users will discover a way to write files
to your anonymous FTP directory. You run the risk of filling up your /var
partition if you use the default setting. It is best to make the anonymous FTP
directory reside in its own dedicated partition.
The configuration file is fairly straight forward as you can see in the snippet below where
we enable anonymous FTP and individual accounts simultaneously.
Descriptions on this and more can be found in the vsftpd.conf man pages.
Anonymous Upload
If you want remote users to write data to your FTP server, then you should create a write-
only directory within /var/ftp/pub. This will allow your users to upload but not access
other files uploaded by other users. The commands you need are:
FTP has many uses, one of which is allowing numerous unknown users to download
files. You have to be careful, because you run the risk of accidentally allowing unknown
persons to upload files to your server. This sort of unintended activity can quickly fill up
your hard drive with illegal software, images, and music for the world to download,
which in turn can clog your server's Internet access and drive up your bandwidth charges.
1) Disable anonymous FTP. Comment out the anonymous_enable line in the vsftpd.conf
file like this:
2) Enable individual logins by making sure you have the local_enable line uncommented
in the vsftpd.conf file like this:
3) Start VSFTP.
4) Create a user group and shared directory. In this case, use /home/ftp-users and a user
group name of ftp-users for the remote users
8) Change the permissions of the files in the /home/ftp-docs directory for read only
access by the group
Remember, you must restart VSFTPD for the configuration file changes to take effect.
1) Check for the presence of a test file on the ftp client server.
[root@smallfry tmp]# ll
total 1
-rw-r--r-- 1 root root 0 Jan 4 09:08 testfile
[root@smallfry tmp]#
Now that testing is complete, you can make this a regular part of your FTP server's
operation.
Conclusion
FTP is a very useful software application that can have enormous benefit to a Web site or
to collaborative computing in which files need to be shared between business partners.
Although insecure, it is universally accessible, because FTP clients are a part of all
operating systems and Web browsers. If data encryption security is of great importance to
you, then you should probably consider SCP as a possible alternative.