The ftp protocol is used to transfer something. Examples of network file services: FTP and NFS. What is meant by FTP server

FTP protocol is included in Internet standards and is used to transmit large amounts of information. The first specifications containing this protocol appeared in 1971. Since that time, the capabilities of FTP have expanded significantly and it is difficult to imagine how users could manage without it if they needed to download or upload several gigabytes of necessary files to online storage. How much time would it take to move the site from local machine to the server, or vice versa? Of course, you can use an archiver, but what if the server does not support this function? It's scary to even imagine. So FTP is quite a useful tool.

The term “protocol” means an agreed upon format for exchanging information between two devices. And itself as “file transfer protocol”, which can be translated as “protocol for transferring files”. The FTP protocol uses a TCP channel. The exchange is built on the client-server principle. It is impossible to transmit using this protocol, since it does not have data protection and clear text is transmitted to the server. Of course, you usually need to authenticate to connect to an FTP server, but don't rely too much on that since the user ID and password are shared in clear text.

The FTP protocol is used to exchange information with FTP sites, which are huge repositories of useful and interesting information. The files on an FTP site are arranged in a tree directory structure, similar to that on your local computer. In order to view the contents of the storage, you can use any browser, but it is better, of course, to use a program specially created for this. Users who prefer to work with command line OS can use the "ftp" command.

Some FTP sites have restrictions on access to their resources. Sometimes, in order to access them, you need to know the login and password of the registered user. Most FTP sites allow you to upload files without entering a password. But it is impossible to record your data on such resources.

How to use the protocolFTPif your OS is not Windows

If you prefer Linux, you can view the documentation for the available operations by typing $ man ftp. And in order to connect to the FTP server, you need to type $ ftp yoursite.at.domain. The most commonly used commands are:

  • binary - changing the mode to transfer binary (non-text) files, for example, pictures;
  • ascii - gear shift text information;
  • cd foldername - change the current directory on the remote computer to a folder named foldername;
  • dir - view all files in the current directory remote computer;
  • help - help on using commands;
  • mget - simultaneous downloading of several files;
  • put filename - used to upload to remote resource local file filename;
  • mput - uploading several files to a remote resource;
  • exit - exit from FTP and exit to the OS.

You can also use programs such as gFTP, FOFF and FileZilla.

How to use the protocolFTPif you prefer Windows

In this case, everything is much simpler, and you Any will do FTP client that is easy to find on the web. Among the free ones, the most popular applications are FileZilla, FTPInfo, WinSCP. Connection via FTP can also be supported by such popular file managers as Total Commander and FAR manager. So, if you don’t use this protocol very often, then you can get by with them.

Well, if you just need to download something one-time, then you can type something like the following command in your browser instead of the URL:

ftp://user: [email protected]:port, in which

site.at.domain - server name,

port - port number to connect (usually 21, and can be skipped).

If you need to connect to anonymous FTP, then use the shortened command notation:

ftp://host.at.domain:port

It happens that some problems arise when connecting via FTP. In this case it makes sense to check Firewall settings and antivirus.

If you've been reading this blog for a long time, you may remember how I decided to collect in it a description of popular (and not so popular) network protocols. Why I need this, you can read in the article A fairly complete description of the SMTP protocol. So I decided to add to the collection the FTP protocol, which is widely used for transferring files.

1. Let's go

As usual, I’ll start right away with an example:

$ telnet example.ru 21
Trying 192.168.0.1...
Connected to example.ru.
Escape character is "^]".
220-Welcome to Pure-FTPd
You are user number 5 of 100 allowed.
Local time is now 17:41. Server port: 21.
220 You will be disconnected after 15 minutes of inactivity.
USER afiskon
331 User afiskon OK. Password required
PASS lamepassword
230-User afiskon has group access to: coders
230 OK. Current restricted directory is /

The FTP server usually runs on port 21. In the example above, the lines starting with numbers are sent by the server, the rest - by the client. Client requests always consist of a single format line COMMAND [arguments], while server responses may contain multiple lines.

The first and last lines begin with three digits representing the response code, followed by text description response, separated from the code by either a space or a dash. If a space is used as a delimiter, then the line is the last in the response (and possibly the only one), otherwise we received the first line of a multi-line response. We've already seen this somewhere, haven't we?

There are five server response groups:

As you can see from the example, it all starts with the server sending code 220. Then the user must log in using the USER and PASS commands. If everything is done correctly, the server will respond to the first with code 331, and to the second with 230. For anonymous login(if it is allowed by the server settings), you should specify “anonymous” as the user name, and your e-mail as the password. In practice, usually either an empty e-mail or something like [email protected].

As you can see, the password is sent to open form, therefore it is highly advisable to encrypt the FTP connection with using SSL(this is called FTPS - FTP plus SSL), or even better - transfer files via SSH using scp, sftp or WinSCP utilities. The first two are available on any Unix system and use the same protocols running on top of SSH to transfer files. WinSCP is written for Windows and looks like Total Commander; it can work with both legacy SCP (Secure Copy) and SFTP (SSH File Transfer Protocol), which appeared only in SSH-2.

2. Let's look around

But something took me to the wrong steppe. After passing authentication (wow, I won’t confuse it with authorization) The FTP server will happily execute our commands. Here is their list:

Team Expected code Description
DELE 250 Delete a file
RMD 250 Delete directory
CWD 250 Go to directory
MKD 257 Create directory
P.W.D. 257 Find out the current directory
QUIT 221 Finish work
TYPE 200 Set transfer type
PORT 200 Switch to active mode
PASV 227 Switch to passive mode
LIST 150, 226 Get directory contents
RETR 150, 226 Download file
STOR 150, 226 Upload file
ABOR 426,226 Cancel transfer
RNFR 350 Select file to rename
RNTO 250 Rename file

Here I have listed only the basic commands, which are enough to write a full-fledged FTP client. The point is that in real conditions FTP servers are very selective about supporting the commands described in RFC959 and RFC3659. So, if we want to get a really working application, and not a spherical horse in a vacuum, we will have to limit ourselves to only the commands from the given list.

The most simple commands- This QUIT, DELE, MKD, CWD and RMD. We simply command and check the code returned by the server. If it is equal to the expected value, then everything is OK, if not, we process the error.

MKD ftp_test
257 "ftp_test" : The directory was successfully created
CWD ftp_test
250 OK. Current directory is /ftp_test
CWD..
250 OK. Current directory is /
RMD ftp_test
250 The directory was successfully removed

If I were writing an FTP client, the code responsible for executing these commands would look something like this:

int code;
char * dir;
// ...
if (code = rawcmd(250 , "RMD %s \r\n", dir) )
printf("Error: %d \n", code) ;
else
printf("All done! \n") ;

A little more difficult with parsing the server response to a command P.W.D.:

P.W.D.
257 "/ftp_test" is your current location

The current directory is transmitted in the only (last?) line of the server response, enclosed in double quotes. If full name current directory contains double quotes, they are replaced with two quotes:

P.W.D.
257 "/ftp""test" is your current location

To rename files, a couple of commands are used − RNFR and RNTO:

RNFR old_file.zip
350 Are you kidding?
RNTO new_file.zip
250 Done!

Apparently, this is an optimization so that the buffer into which the server reads client commands is of the order of the maximum allowable length of the full file name, and not twice as long. In 1971, when the protocol was created, this could have been important.

Team TYPE allows you to set the file transfer mode. Example:

TYPE E
200 TYPE is now EBCDIC
TYPE A
200 TYPE is now ASCII
TYPE I
200 TYPE is now 8-bit binary

As far as I can tell, today this command is already outdated and all data can be safely transmitted in binary format (TYPE I). Quote from Wikipedia:

The first computers used a byte-sized machine word format, a double machine word, not a multiple of 8. They were usually multiples of six. Eight bits per byte were adopted during the development of the machine instruction system for the IBM System/360. It has become international standard And since the early 1970s Most computers use bytes consisting of 8 bits and machine words in multiples of 8.

3. Let's take action

A feature of the FTP protocol is that it uses different connections. This is generally a normal design decision. We don’t know what is written in these files, and if we transmit them along with commands, we will have to somehow encode the contents of the file to distinguish it from commands. Why increase the amount of traffic and complicate the protocol when you can simply open a new connection and send the file as is?

When establishing a new connection, someone must actually connect, and someone must accept the connection. If the client opens a port and the server connects to it, the file transfer mode is called active. Otherwise, it is passive. Due to the fact that many Internet users today sit behind NAT, passive mode is usually used. And this is not very good, because the number of ports on the server is limited.

What’s interesting is that it is possible to transfer files from one FTP server to another directly. But since this feature was often used in DDoS attacks, it is now disabled almost everywhere.

To switch to passive mode, use the command PASV, to switch to active - PORT:

PORT 192,168,10,1,21,133
200 PORT command successful
PASV
227 Entering Passive Mode (192,168,0,1,21,216)

As you might guess, the IP address and port for the connection are encoded using numbers. Let's say we are in passive mode and want to establish a data connection:

$ telnet 192.168.0.1 `expr 21 \* 256 + 216`
Trying 192.168.0.1...
Connected to example.ru.
Escape character is "^]".

After which we can, for example, view the contents of the current directory by using the command LIST:

LIST
150 Accepted data connection
226-Options: -a -l
226 5 matches total

Let's look at the telnet output:

drwx------ 5 afiskon coders 512 Jul 7 11:35 .
drwx------ 5 afiskon coders 512 Jul 7 11:35 ..
drwxr--r-- 3 afiskon coders 512 Jun 6 14:30 website
drwxr-xr-x 2 afiskon coders 1024 Jul 7 00:16 logs
drwxr--r-- 2 afiskon coders 512 Jun 6 14:30 tmp
Connection closed by foreign host.

Downloading and uploading files is done in exactly the same way, only the commands are used RETR (file) And STOR (file) respectively. The RETR, STOR, and LIST commands can be interrupted mid-execution using the command ABOR, in response to which the server should respond with 426 “transfer interrupted”, and then with 226 “cancellation of the operation was successful.”

4. Conclusion

This is where I will probably end my story. The result was 9 KB of text versus 130 KB of RFC959. Using this article, it is quite possible to write a simple FTP client or server, I checked! The most important thing is to test it for compatibility with as many software as possible, because, as I already noted, in the FTP world, few people strictly follow the RFC. And lastly, remember the golden rule “Be liberal with input, strict with output.”

FTP (File Transfer Protocol file transfer protocol ) standard protocol, designed for transferring files over TCP networks, built on a client-server architecture and using different network connections to transfer commands and data between client and server.

The server provides client access to data (usually files and directories) to the client either anonymously or after authentication, in which the login and password are transmitted in clear text. Can be used SSH protocol to encrypt login, password and transmitted data.

The protocol is quite simple; it uses various TCP connections for commands and for transmitted data. Usually this is 21 ports for control commands and 20 for data transmission (otherwise, this may be different). After TCP settings connections to 21 ports communication FTP client This happens with the server using fairly simple text commands.

In accordance with RFC 959, the Control Flow Server (21 ports) responds with three-digit ASCII status codes with an optional text message.

There are 2 operating modes of the FTP protocol: active and passive.

In active mode, the client creates a TCP control connection with the server on port 21 and sends its IP address and an arbitrary client port number to the server, and then waits until the server starts a TCP connection with this address and port number.

In passive mode, the client uses control flow ( TCP port 21) to send the PASV command to the server, and then receives from the server its IP address and port number, which is then used by the client to open a data stream from an arbitrary client port to the received address and port.

Knowledge of modes FTP work helps if you need to connect to FTP server or raise it on a network that is hidden behind NAT and/or protected by a firewall, which, as you might guess, is not uncommon. If the client cannot accept incoming connections on arbitrary port, then you need to configure the server in passive mode, then incoming connections to the client will not be required, but the server must be ready to accept incoming connection to preset ports. Active mode is suitable for a server whose administrator is not ready to accept incoming connections on ports other than 21, but in this case the client will be able to connect only if it itself accepts incoming connections. So in any case, someone will have to open additional ports.

Four data representations can be used during transmission:

    ASCII - used for text.

    Image mode (binary) - The sending device sends each file byte by byte, and the recipient stores the byte stream upon receipt.

    EBCDIC - Used to transfer plain text between hosts in EBCDIC encoding.

    Local mode - allows two computers with identical settings send data to own format without conversion to ASCII.

Data transfer can be carried out in any of three modes:

    Stream mode - data is sent as a continuous stream, freeing FTP from performing any processing.

    Block mode - FTP breaks the data into several blocks (header block, number of bytes, data field) and then transmits them to TCP.

    Compression mode—data is compressed using a single algorithm.

FTP uses a login and password for authentication to provide access. The username is sent to the server with the USER command, and the password is sent with the PASS command. If the information provided by the client is accepted by the server, then the server will send an invitation to the client and the session begins. The login and password are transmitted in clear text, so this method cannot be called secure. The FTP server can also provide anonymous access to the data, that is, for everyone, without asking for a login and password.
There are extensions and ways to safe transfer data and authentication, for example: FTPS SFTP FTP via SSH.

I will give an example of an FTP session with my comments. Here is the output of the commands (only in the control channel, of course) that the FTP client sent to the server and the server’s responses without abbreviations (I will replace some parameters with asterisks, for example the password for security reasons):

Status: - this is a message from the FTP client; when exchanging commands with FTP “manually” you will not see these messages. Response: - these are the responses of the FTP server Command: - these are the commands that the client sends to the server (in manual mode you will enter them from the keyboard).

S tatus: Connecting to 37.140.*.* ...
Status: Connected with 37.140.*.*. Waiting for welcome message...
Response: 220 (vsFTPd 2.2.2) - so, we knock on port 21 37.140.*.* and they tell us that vsFTPd is working there
Command: USER ********* - send username
Response: 331 Please specify the password. - username accepted
Command: PASS ******** - send the password
Response: 230 Login successful. -password accepted
Command: SYST - "And what OS do you have?" we ask
Response: 215 UNIX Type: L8 - “and this is it” the server will answer
Command: FEAT - what can you do, server?
Response: 211-Features: - and here's what :)
Response: EPRT
<... Не будем оглашать весь список...>
Response: UTF8
Response: 211 End - the server has finished listing the functions
Command: OPTS UTF8 ON - talk to us in UTF-8 encoding
Response: 200 Always in UTF8 mode. - sure, not a problem
Status: Connected - We are the ones who revive the connection.
Command: PWD - show us the working directory
Response: 257"/" - on the! this is the name of the working directory (we have /)
Command: TYPE A - but first we’ll set the data presentation mode
- OK
Command: PASV - and ask to go into passive mode
Response: 227 Entering Passive Mode (37,140,192,202,249,140). - received a list of ports
Command: LIST - give me a list of the directory contents

- at this point we received the table of contents via the data channel
Command: TYPE A
Response: 200 Switching to ASCII mode.
Status: Retrieving directory listing...
Command: CWD www - change the working directory to www
Response: 250 Directory successfully changed. -response "ok"
Command: PWD - again request the working directory
Response: 257 "/www" - now he is /www
Command: TYPE A - and selecting the data presentation mode
Response: 200 Switching to ASCII mode.
Command: PASV - again in passive mode
Response: 227 Entering Passive Mode (37,140,192,202,252,174).
Command: LIST - request the table of contents of the catalog
Response: 150 Here comes the directory listing.
Response: 226 Directory send OK.
Status: Directory listing successful - we received the table of contents and now
Status: Starting download of /www/google8f2c0456e362dfaa.html - we want to download the file
Command: TYPE A - for this we will select the type again
Response: 200 Switching to ASCII mode.
Command: PASV - and data transfer mode
Response: 227 Entering Passive Mode (37,140,192,202,254,190).
Command: RETR google8f2c0456e362dfaa.html - and say: “Give it to the file”
Response: 150 Opening BINARY mode data connection for google8f2c0456e362dfaa.html (53 bytes).
Response: 226 Transfer complete. - and now the file was received via the data channel
Status: Download successful
Status: Retrieving directory listing...
<... Пропустим некоторые повторяющиеся действия...>
Command: MKD fff - and here we created a folder
Response: 257 "/www/moop-nz.ru/02-uslugi/fff" created
Command: RNFR /www/moop-nz.ru/02-uslugi/fff - and we want to rename the fff folder
Response: 350 Ready for RNTO.
Command: RNTO /www/moop-nz.ru/02-uslugi/eee - to the eee folder
Response: 250 Rename successful. - operation was successfully completed
<... Пропустим некоторые повторяющиеся действия...>
Command: RMD /www/moop-nz.ru/02-uslugi/eee/ - delete the previously created folder
Response: 250 Remove directory operation successful. - everything worked out
Status: Connected
Status: Starting upload of C:\12345\12345 001.jpg - start uploading the file to the server
<... Пропустим некоторые повторяющиеся действия...>
Command: TYPE I
Response: 200 Switching to Binary mode.
Command: PASV
Response: 227 Entering Passive Mode (37,140,192,202,243,234).
Command: STOR 12345 001.jpg - this time we send the file to the server
Response: 150 Ok to send data.
Response: 226 Transfer complete.
Status: Upload successful
Status: Retrieving directory listing...
Command: TYPE A
Response: 200 Switching to ASCII mode.
Command: PASV
Response: 227 Entering Passive Mode (37,140,192,202,251,25).
Command: LIST
Response: 150 Here comes the directory listing.
Response: 226 Directory send OK.
Status: Directory listing successful
Command: DELE /www/moop-nz.ru/02-uslugi/12345 001.jpg - and delete it finally
Response: 250 Delete operation successful.

People have created a lot of FTP servers and clients (after all, the protocol has been around since 1971).

Eat special programs working as an FTP client, such as: FileZilla, gFTP, cURL, lftp and many others, but now almost any browser can work as an FTP client ( Mozilla Firefox, Konqueror, Opera, Yandex.Browser, Google Chrome, Internet Explorer, etc.) or file manager ( Midnight Commander, Krusader, GNOME Commander, Konqueror, Nautilus, Dolphin, FAR Manager, Total Commander, Windows Explorer, etc.), so there is no need to use special programs (although I sometimes use gFTP).

In order to set up your FTP server with preference and authentication, you will need a special program that will act as a server. There are also many such programs, including: vsftpd, ProFTPD, Pure-FTPd, glFTPd, oftpd, Serv-U File Server and many others.

It seems in general outline It’s clear what FTP is and why it’s needed.

  • Back
  • Forward
  • Telemetry in Windows 10. Disable it, don’t disable it, you’ll still get the best solution
  • Go. The computer was able to beat the champion of the three-time European champion in the game Go
  • New "gifts" from Microsoft - "stability" and "privacy"

    The world-famous corporation once again pleased us with news: After the release of the next patch, the built-in tool for Bitlocker encryption stopped working, and Microsoft can't...

We released new book"Content marketing in in social networks: How to get into your subscribers’ heads and make them fall in love with your brand.”

Subscribe

More videos on our channel - learn internet marketing with SEMANTICA

This technology is one of the most popular for downloading and uploading data from/to remote servers, dispersed throughout the world.

Ftp systems are used to create websites. All information related to the Internet resource is stored on the FTP server. When a developer needs to make some adjustments to the site, he goes to the server, downloads the file that needs to be corrected, and then uploads it back. And that's it, the change took effect. It's fast and convenient.

What does an FTP server look like?

The visual presentation depends on the system through which you are logging in. There are special programs like FileZilla, in which data is displayed in the form of the familiar Total Commander.


Many hosting sites have their own management system, which also looks like a familiar set of folders and files.

FTP server features

Let's take a closer look at the technical aspects and tell you what an ftp server is and how it works.

The main function of FTP is to transfer files.

In addition to uploading and downloading information, various commands, with which you can manage files and directories:

  1. Authentication required.
  2. Availability of a dedicated channel for each connection.
  3. Supports 2 data transmission modes: text and binary (in binary system). The second option reduces time and traffic.
  4. Use of multiple connections, at least two-channel. Through one, control commands are transmitted and processed responses are returned. With the help of others, file transfer is carried out based on a dedicated channel for each.

How to connect to an FTP server

To enter the server, you need to fill out an authorization form, in other words, pass authentication. After entering the login (user) and password (pass), this information is transferred to the system. If accepted, the client will receive an invitation and the work session will open.

There are login options without specifying registration data. In this case, the options available to the visitor will be limited.

There is another option for logging into an FTP server - anonymous access. By default, login occurs when you enter the login “anonymous”; the spelling may differ in the case of letters. However, the most common method is when they offer to log in using email address. This access option is used by many FTP hosts that send out software updates.

To connect, you can use a web browser or file managers such as Total Commander, FileZilla. Through the browser, you will be able to view and download files, but you will not be able to make changes.

It is more convenient to work through FileZilla client program(can be downloaded in the public domain).

Create a new connection as follows:

  • In the “Host” field, enter the FTP server address.
  • Fill in the fields “User name”, “Password” and, if necessary, “Port”.

Where can I get the address? If you connect to a server hosted on a host, the site owner has all access; it was provided by the provider.

What else is FTP used for?

Website files are the most common use case, but that's not all that resides on FTP servers.

There you can store any working or personal information large volumes, as an option, photographs, videos.

Almost any information that is used daily by millions of people is posted on FTP storages. These are software, demo versions of programs, e-books, legislative acts, articles, films, music - everything that can be formatted in a file representation. Catalogs have been created on the Internet containing terabytes of useful or entertaining information. Typically available anonymously and does not require payment.

Disadvantages of FTP servers

Weak protection against hacking and attacks. Due to technical features, not only servers, but also clients can be damaged. Therefore, confidential information should not be stored on them.

There is no authentication of the source of the data transmission packet, which leads to vulnerability to DDoS attacks.

FTP is a standard mechanism for copying a file from one host to another. Transferring files from one computer to another is one of the large number common tasks, the execution of which is expected from organized network and interactions between networks.

Although transferring files from one system to another seems like a simple and straightforward task, there are some issues that need to be resolved first. For example, two systems may use different file naming conventions. The two systems may have different ways of presenting texts and data. The two systems may have different directory structures. FTP solves all these problems in a very simple and elegant way.

FTP is different from other type of applications client-server in that it establishes two connections between hosts. One connection is used to transmit data, the other is used to control information (commands and responses). Separation of commands and transfers control data makes FTP more efficient. Connection control uses very simple rules for communication. We only need a command line or a response line for transmission. On the other hand, a data connection needs more complex rules due to the variety of data types.

FTP uses two defined ports: port 21 for management and port 20 for data transfer.


Rice. 13.5.

File type

FTP can transfer over a data connection following types files:

  • ASCII file. This is the default format used for broadcasting text files. Each character is encoded using NVT ASCII characters. The transmitter converts the file from its native representation to NVT ASCII, and the receiver converts the NVT ASCII characters to its native representation.
  • EBCDIC file. If both ends of the connection use EBCDIC encoding, the file can be transferred using EBCDIC encoding.
  • Image file. This file is the default format for transferring binary files. The file is sent as a continuous stream of bits without any interpretation or encoding. It is mostly used to transfer binary files such as a compiled program.

If the file is encoded in ASCII or EBCDIC, other attributes must be complemented to determine whether the file can be printed:

  1. Prohibited for publication. This is the default format for transferring text files. The file does not contain "vertical" print specifications. This means that the file cannot be printed without pre-processing because it does not contain characters that are interpreted for vertical movement print head. This format is used for files that will be accumulated and processed later.
  2. TELNET. In this format, the file contains NVT ASCII vertical characters such as CR (carriage return), LN (line feed), NL (new line), and VT (vertical tab). These files can be printed after transfer

Data structure

FTP can transfer a file over a data connection using one of the following data structure interpretations:

  • File structure (default). This file has no structure. It's a continuous stream of data.
  • Record structure. This file is separated within a record. It can only be used with a text file.
  • Page structure. This is a file divided into pages, each page has a number and page title. Pages can be accumulated or reached using random or sequential access.

Transfer Modes

FTP can transfer a file over a data connection using one of the following three transfer modes:

  • Stream mode. This is the default mode. Data is delivered from FTP to TCP as a continuous stream of data. TCP is responsible for breaking the data into appropriately sized segments. If the data is just a stream of bytes ( file structure), then no end-of-file sign is needed. The end of file in this case is the release of the data connection by the sender. If the data is divided into records (structure by record), each record will have a one-byte end of record character (EOR - end of record).
  • Block mode. Data can be delivered from FTP and TCP in blocks. In this case, the block is preceded by a three-byte header. The first byte is called the block descriptor, the next two bytes determine the block size in bytes.
  • Compressed mode. If the file is large, the data may be compressed. The compression method uses normal length encoding. In this method, the sequential re-occurrence of a block of data is replaced by a single occurrence and number of repetitions. In the text of a file, this is usually a space (emptiness). IN binary file null characters are usually compressed.

FTP uses a management connection to establish communication between the client management process. During this communication, commands are sent from the client to the server, and responses are sent from the server to the client (Figure 13.6).


Rice. 13.6.