The FTP Protocol for Server Access
This protocol has been established in the aim of facilitating exchange of data between computers. FTP allows you to tranfer data between two servers, or servers and clients, and nearly all servers support this protocol. FTP tools are most often used by webmasters to transfer files on the server, and net surfers to download them. Commands of directory management may help to update a website
FTP and HTTP have same model
HTTP (HyperText Transfer Protocol) is the data transfer protocol on the
Web (World Wide Web) while FTP (File Transfer Protocol) is a protocol for
exchanging data between computers.
HTTP works also in the client/server mode, but the client is called "user agent" and is a browser or other tool to access the Web, such as Chromeless which can put web applications as icons on the computer desktop.
The connections are made both in HTTP and FTP as a request in TCP (Transmission Control Protocol). HTTP uses methods (GET, POST, HEAD) while FTP makes use of commands, and the first has its own error codes, as the code 404 (access unavailable) that users are familiar with...
Description of the access to the server
FTP provides a set of commands needed for the transfer and the management
- Download and upload.
- View the contents of directories
- Rename or delete files, change permissions, etc.
FTP is based on the TCP/IP protocol, which is also the one of Internet or
Intranet. The FTP protocol is operating system independent, on servers and
There is a connection established for commands and another for data transfer.
- The connections are made in both directions, between two computers that are both servers or clients. But we can connect as a client only.
- The data connection is not permanent. Sending data is simultaneously in both directions.
Common operations begin with a client's connection, your computer for example, on the server, which usually asks you a login and a password. But anonymous connection is also possible. This mode is used for example by Sourceforge for sending files that are stored on a storage area, before to be be checked and integrated into the site
The connection can operate in active or passive modes. In the active mode,
the server opens a connection on the client to send data (even if it is the
client who pass commands), while in passive mode, it is the client computer
that initiates the transfer.
The active mode could face to firewalls, intended to protect the computer against malicious external intrusions.
FTP may be used in PHP
The PHP language offers a comprehensive enough list of functions to manage
the contents of a website by FTP, making it possible to realize the software
on this site.
In addition to the commands of connection and disconnection, the main functions are ftp_get to download a file and ftp_put to send it. Ftp_chdir, ftp_mkdir can change directories, or create one. You can also obtain the size of a file, and so on.
Some functions or parameters depend on compatibility with the server, and that makes the achievement of universal software rather difficult.
- A demonstration of the use of FTP functions in PHP.
- And a list of FTP functions of PHP may be taken from this Scriptol interface.
Binary and ASCII modes
As this can be seen when using PHP functions, the transfer method can be
made either textual in ASCII, or binary.
In the first case, the files are saved in the format of the target operating system. Text file in Windows' format sent from a Windows PC will be stored in Unix format if the OS of the remote computer is Unix. Instead in binary mode files are stored as is, what is appropriate for images.
If you are using a FTP program, it will not be able to adapt the transfer mode to each file, and thus it uses only the binary mode for all files, therefore the format of text files will not be converted. This is crucial for the .htaccess file. Use an editor that allows to choose the OS format.
Security requires an reinforced protocol
FTP is not secure because the password is not encrypted and can be intercepted
by spyware. As a general rule, transfers are not encrypted and can be intercepted.
To avoid this, the SFTP protocol (SSH File Transfer Protocol), has been developed. It differs from FTP and requires its own tools.
The other one is secure FTPS (FTP over SSL), which adds an SSL encryption.
Several demonstration scripts, and more sophisticated programs are available on this site:
- PHP FTP Synchronizer. Updating a Web site from a local directory.
- FTP Check. Testing connection to a server.
- FTP Download. Complete program to download a file.