FTP scripts

The FTP protocol was designed to simplify the exchange of data between computers. FTP allows communication between two servers, or one server and clients and almost all servers support this protocol.
FTP tools are most often used by webmasters to transfer files to the server, and Internet users to download them. Directory management commands update the Web site.

FTP and HTTP have the same model

HTTP (HyperText Transfer Protocol) is the World Wide Web protocol, and FTP (File Transfer Protocol) is the protocol for exchanging data between computers.
HTTP also works in server client mode, but here the client is called a user agent (user agent) and is a browser or other web access tool, such as Mozilla's Chromeless, which allows you to place web applications on your computer's desktop.
Connections are established in both HTTP and FTP on request from the user agent using the Transmission Control Protocol (TCP).
HTTP uses its own methods (GET, POST, HEAD), while FTP uses commands, and the former has its own error codes, such as 404 (no access possible), which Internet users know well!

Server Access Template Description

FTP offers a set of commands needed to transfer and manage files:
- Download, one way or another.
- View the contents of directories.
- Rename or delete files, change permissions.

FTP is based on TCP/IP, which is also an Internet or intranet protocol.
The protocol is independent of the server or client operating system.
There is a connection for commands and another for data.
- Connections are made in both directions, between two computers that are servers or clients. But we can enter as a client alone.
- Data connection is not permanent. Data transmission occurs simultaneously in both directions.
Any operation begins with connecting a client, for example, a computer on a server, which usually requires a login or password from you.
But anonymous communication is also possible. This mode is used, for example, by Sourceforge to send files that are placed in the storage area with validation and integration at the site.

The connection can be active or passive. In active mode, it is the server that opens the connection on the client to send data (even if it is the client who places orders), and in passive mode, the client orders the transfer.
The active mode may collide with a firewall, which in this case incorrectly protects the computer from external intrusions.

FTP и PHP

PHP offers a fairly complete list of commands for managing site content via FTP, which made it possible to implement software on this site.
In addition to the connect and disconnect commands, the main functions are:

Some features or options depend on server compatibility, making it difficult to create generic software.

FTP download to PHP

Access to ftp begins by connecting to a website on the server, depending on its form address: ftp.nomdomaine.tld.

int x = ftp_connect("ftp.iqlevsha.ru")

This function asks for a short time and returns the number that will be used for all subsequent ftp functions.
Thus, at the end of the session, we will do the following:

ftp_close(x)

After logging in, the login and password are issued:

boolean res = ftp_login(x, login, motdepasse)

If the user is recognized, the function returns true (true), and you can perform the necessary operations.
To send a file to the server:

ftp_put(x, nomfichier, nomlocal, mode)

To check out a file on the server:

ftp_get(x, nomfichier, nomlocal, mode)

FTP_ASCII mode for a text file and FTP_BINARY for a binary file, such as an image.

Source archive at the bottom of the page .

Binary and ASCII modes

As you can see when using PHP functions, the transmission method can be either text, in ASCII format, or binary. In the first case, the files are saved in the format of the target operating system. Thus, you can send a text file from a Windows computer that will be stored in Unix format if the server is under Unix.
On the contrary, in binary mode, files are stored as is, which is suitable for images.
If FTP software is used, it will not be able to adapt the transfer method to each file and will use binary mode for all files, so the text format will not be converted. This is crucial for the .htaccess file. Use the editor to select the format depending on the operating system.

Security requires enhanced protocol

FTP mode is insecure because an unencrypted password can be intercepted by spyware. In general, transmissions are not encrypted and therefore can be intercepted.
To avoid this drawback, the SSH File Transfer Protocol (SFTP) was developed. It is different from FTP and requires its own tools. Another secure protocol is FTPS (FTP over SSL), which adds SSL encryption.

Director's scripts

Displays

Director's scripts

Documents and references