Download, upload and delete files from an FTP server from the command line. How to download files from FTP from the Windows command line Ftp utility in the windows command line

Data transmission control control commands exchanged between the Server Protocol Interpreter and the User Protocol Interpreter can be divided into three large groups:

System access control commands.

Flow control commands.

FTP service commands.

Let's look at a few of the most typical teams from each group. Among the system access control commands, the following should be noted:

USER. Typically, this command opens an FTP session between the client and server. The command argument is the name (identifier) ​​of the user to work with the file system. This command can be issued not only at the beginning, but also in the middle of the session if, for example, the user wants to change the identifier on behalf of which actions will be carried out. In this case, all variables related to the old identifier are released. If communication occurs during an ID change, the exchange ends with the old user ID.

PASS. This command is issued after entering the user ID and contains the user password as an argument. Let us remind you that FTP authentication data is transmitted over the network in clear text, so the user must take additional measures to ensure the security of the channel.

CWD. The command allows users to work with various remote directories file system. The command argument is a string indicating the path of the remote file system directory in which the user wishes to work.

REIN. Reinitialization command. This command clears all current user variables and resets connection parameters. If data is being transferred at the time the command is issued, the transfer continues and ends with the same parameters.

QUIT. The command closes the control channel. If data is being transmitted when a command is issued, the channel is closed after the end of data transmission.

Teams flow control set data transfer parameters. All parameters described by these commands have a default value, so flow control commands are used only when it is necessary to change the value of the default transfer parameters. Flow control commands can be issued in any order, but they must all precede the FTP service commands. The following data flow control commands should be highlighted:

PORT. The command assigns the address and port of the host that will be used as an active participant in the connection over the data link. The command arguments are a 32-bit IP address and a 16-bit connection port number. These values ​​are divided into six 8-bit fields and are represented in decimal form: h1, h2, h3, h4, p1, p2, where hN are the address bytes (high to low) and pN are the port bytes (high to low) .



PASV. This command is sent to the module, which will play a passive role in the data transfer ("listen" to the connection). In response to this command there should be a line containing the address and port of the host that is waiting for a connection in the PORT command format - "h1, h2, h3, h4, p1, p2".

Teams TYPE, STRU, MODE determine, respectively, the type of transmitted data (ASCII, Image and others), the structure or format of data transmission (File, Record, Page), the transmission method (Stream, Block and others). The use of these commands is very important when building communication in heterogeneous environments and very different operating and file systems of the communicating hosts.

Teams FTP service determine the actions that need to be taken with specified files. Typically, the argument to commands in this group is a file path. Syntax specified path must satisfy the command handler file system format requirements. The FTP service commands include the following:

RETR. This command instructs the Server Data Transfer module to pass a copy of the file specified by this command parameter to the Data Transfer module at the other end of the connection.

STOR. The command instructs the Server Data Transfer Program module to receive data over the data link and save it as a file whose name is specified by the parameter of this command. If such a file already exists, it will be replaced with a new one; if not, a new one will be created.

Teams RNFR And RNTO must follow one after another. The first command contains the old file name as an argument, the second - the new one. Consecutive Application these commands renames the file.

ABOR. The command instructs the server to interrupt the execution of a previous service command (for example, a file transfer) and close the data channel.

Team DELE deletes the specified file.

Teams MKD And RMD, respectively, create and delete the directory specified in the argument.

Using commands LIST And NLST you can get a list of files in a specified directory.

All FTP protocol commands are sent by the "User Protocol Interpreter" in text form - one command per line. Each command line - identifier and arguments - ends with the characters . The command name is separated from the argument by a space character - .

The command handler returns a three-digit code for processing each command. Processing codes form a specific hierarchical structure and, as a rule, a certain command can only return a certain set of codes. The command processing code is followed by a space character - , followed by explanatory text. For example, the success string for an operation looks like this: "200 Command okay.

Below is an example of working with the FTP protocol. Designations: S - server, U - user.

S: 220 Service ready for new user

> S: 331 User name okay, need password

S: 230 User logged in, proceed

U: RETR test.txt

S: 150 File status okay; about to open data connection

<Идет передача файла...>

S: 226 Closing data connection, file transfer successful

S: 200 Command okay

U: STOR /home/images/first.my

S: 550 Access denied

Commands and responses are sent over the control connection between the client and server in NVT ASCII format. At the end of each command or response line there is a CR, LF pair.

The only Telnet commands (beginning with IAC) that can be sent by a client to a server are the process interrupt command ( ) and Telnet synchronization signal ( in urgent mode). We will see that these two Telnet commands are used to stop a file transfer or to send a request to the server while the transfer is in progress. If the server receives a command from a client with a Telnet option (WILL, WONT, DO or DONT), it responds with either DONT or WONT.

Commands consist of 3 or 4 bytes, namely uppercase ASCII characters, some with optional arguments. The client can send more than 30 different FTP commands to the server. Table 5.1 shows some of the most widely used commands, most of which we'll cover in this chapter.

Table 5.1

Common FTP commands.

In the examples we will see that some commands are exactly the same as what the interactive user enters as FTP commands. In this case, they are sent over the control connection, but some user-entered commands generate multiple FTP commands, which in turn are sent over the control connection.

Standard Windows utility "FTP client" from command line(CMD) - for backup or downloading files without your participation (automatically).

  1. open - connection to a remote host via FTP;
  2. cd - transition to another directory on the server;
  3. bin - binary mode of data transfer between server and client;
  4. put - transfer files to FTP;
  5. bye - end the session with the server and exit.

In order to master the Windows FTP client and start working with it, let's try to connect to any FTP server in console mode, for example 213.43.125.75.

We enter open 213.43.125.75 (this is the IP address of the FTP server), instead we enter the address or domain of the FTP server you need, you will be required to enter a username and password. After successful authorization, we create a folder for storing archives on FTP, without hesitation, we call it backup (the folder is created mkdir command). Now we go to the directory we created with the following command: cd back-up. At the next stage, we copy the file to the server, which requires setting the file transfer mode to “binary” using the bin command without any parameters. And now we enter put D:/back-up/back-up.zip, where the parameter of the put command will be the full path to the copied file. When copying, you can specify a mask in the directory, for example: D:/back-up/*.zip (*.zip - all files with the "zip" extension). After copying, close the connection to the server with the bye command.

So that our FTP client does everything automatically, without asking questions, we will create a script for it. Below is a text file (let's call it back-up.ftp and save it to the root of the C:/ drive - for ease of use and writing in the startup line), containing a number of commands for FTP client, which will be automatically executed when you launch the FTP client from the command line.

Open 213.43.125.75 (instead of numbers - the address of the desired FTP server)
user
password
cd back-up (go to an existing directory on FTP server)
bin (Transmission mode - binary)
put D:/back-up/back-up.zip (Path to the file on your computer)
bye (End connection)

The result should be a back-up.ftp file with the following content:

open 213.43.125.75
user
password
CD back-up
bin
put D:/back-up/back-up.zip

FTP (File Transfer Protocol) is a popular network protocol, which is used to copy files from one computer to another in local network, or on the Internet. FTP is one of the oldest application protocols, appearing long before HTTP, and even before TCP/IP, in 1971.

The FTP protocol is vulnerable, meaning FTP cannot encrypt its traffic, all transmissions are plaintext, so usernames, passwords, commands and data can be read by anyone able to intercept the packet over the network. For secure data transfer, the SFTP (Secure File Transfer Protocol) protocol is used. Unlike standard FTP, it encrypts both commands and data, preventing passwords and sensitive information from being transmitted openly over the network. SFTP is similar in functionality to FTP, but because it uses a different protocol, standard FTP clients cannot communicate with an SFTP server and vice versa. Next, we will look at the basic commands for working with the FTP program.

FTP client is one of the most Linux distributions. Let's start by launching the program and ftp connection and, of course, consider the basic commands for downloading from an ftp server and uploading to ftp, creating directories, deleting files, etc. In this article we will describe only the basic commands, and at the end of the article we will provide help and a manual from the console - you can always find out about the purpose of the command and its syntax, as well as about all the available commands on a specific ftp server.

FTP connection

To start an FTP connection, just enter the command ftp<сервер> For example:

ftp test.hostingthutor.com

After pressing enter, the command output will be as follows:

Connected to test..55.5.11).
220 test..
Name (test.site:ftpuser):

Another way to connect is to run ftp from the console, and after that connect to the ftp server using the command open:

ftp
ftp> test.site

In addition, it is possible to connect via IP:

ftp 114.55.5.11

Or with this request ftp This e-mail is being protected from spambots. To view it, your browser must have Javascript support enabled, that is:

ftp This e-mail is being protected from spambots. To view it, your browser must have Javascript enabled
230 User ftpuser logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

From the message it is clear that the binary (binary) transfer type is used to transfer files. Binary file transfer mode is the transfer of files in the form in which they are stored on the FTP server. Ascii (text) mode is used to transmit only text files. You can enter commands ascii or binary to switch between transmission modes. Binary mode must be used for all non-text file types - images, archives, programs, etc.

So, let's move on to the commands for navigating and going through the ftp server directories:

pwd - the command will show the current directory on the ftp server:

ftp>pwd
257 "/" is the current directory

ls - the command will show a list of files and directories in the current directory:

ftp>ls
227 Entering Passive Mode.
150 Opening ASCII mode data connection for file list
-rw-r--r-- 1 ftpuser ftpuser 3034978 Jun 31 19:02 file1.tar.gz
-rw-r--r-- 1 ftpuser ftpuser 30842294 Jul 31 20:08 file2.tar.gz
-rw-r--r-- 1 ftpuser ftpuser 67798316 Jul 31 19:46 file3.tar.gz
-rw-r--r-- 1 ftpuser ftpuser 6001252 Jan 17 12:02 file4.zip
-rw-r--r-- 1 ftpuser ftpuser 31386394 Jan 17 11:28 file5.tar.gz
drwxr-xr-x 2 ftpuser ftpuser 4 Jan 17 20:23 www
-rw-r--r-- 1 ftpuser ftpuser 48546694 Jan 17 11:33 file6.zip
226 Transfer complete

CD<имядиректории> - command to go to the desired directory:

ftp> cd www
250 CWD command successful

We check with the team pwd :

ftp>pwd
257 "/www" is the current directory

mkdir<имя директории> - creating a new directory (directory):

ftp> mkdir tmp
257 "/tmp" - Directory successfully created

rmdir<имя директории> - deleting a directory (directory):

ftp> rmdir tmp
250 RMD command successful

Deleting files on an ftp server

delete<имяфайла> - deletes a file on a remote ftp server:

ftp> delete test1.sql
250 DELE command successful

Downloading files from ftp

get - download the file to your local machine. get fileName or get fileName newFileName

ftp>get file.zip
local: file.zip remote: file.zip
227 Entering Passive Mode.

226 Transfer complete
486694 bytes received in 0.229 secs (6.5e+04 Kbytes/sec)

Download file.zip to your local machine as file2.zip:

ftp> get file.zip file2.zip
local: file2.zip remote: file.zip
227 Entering Passive Mode.
150 Opening BINARY mode data connection for file.zip (486694 bytes)
226 Transfer complete
486694 bytes received in 0.306 secs (9.4e+04 Kbytes/sec)

Using the command get from the remote ftp server, files are copied to the current local directory. To change the current local directory you need to use the command lcd:

lcd<путь> - change the current directory on the local machine:

ftp> lcd /root
Local directory now /root

To download multiple files from remote ftp server to your local machine, you can use the command mget .

ftp> mget *.sql
mget test2.sql? y
227 Entering Passive Mode.
(23957080 bytes)
226 Transfer complete
23957080 bytes received in 0.233 secs (1e+05 Kbytes/sec)
mget test1.sql? y
227 Entering Passive Mode.
(11873185 bytes)
226 Transfer complete
11873185 bytes received in 0.135 secs (8.6e+04 Kbytes/sec)

The download of each file must be confirmed (yes / no) y /n .

Another download option mget :

ftp> mget test1.sql test2.sql
mget test1.sql? y
227 Entering Passive Mode.

226 Transfer complete
11873185 bytes received in 0.101 secs (1.1e+05 Kbytes/sec)
mget test2.sql? y
227 Entering Passive Mode.

226 Transfer complete
23957080 bytes received in 0.204 secs (1.1e+05 Kbytes/sec)

Uploading a file to an ftp server

put<имяфайла> - command to upload one file to an ftp server.

ftp> put test1.sql
local: test1.sql remote: test1.sql
227 Entering Passive Mode.
150 Opening BINARY mode data connection for test1.sql
226 Transfer complete
11873185 bytes sent in 0.129 secs (9e+04 Kbytes/sec)

For upload multiple files you can immediately use the command mput :

ftp> mput test1.sql test2.sql
mput test1.sql? y
227 Entering Passive Mode.
150 Opening BINARY mode data connection for test1.sql
226 Transfer complete
11873185 bytes sent in 0.0964 secs (1.2e+05 Kbytes/sec)
mput test2.sql? y
227 Entering Passive Mode.
150 Opening BINARY mode data connection for test2.sql
226 Transfer complete
23957080 bytes sent in 0.354 secs (6.6e+04 Kbytes/sec)

Each file upload must be confirmed. y / n (Not really).

Another command option mput :

ftp> mput *.sql
mput test1.sql? y
227 Entering Passive Mode.
150 Opening BINARY mode data connection for test1.sql
226 Transfer complete
11873185 bytes sent in 0.0985 secs (1.2e+05 Kbytes/sec)
mput test2.sql? y
227 Entering Passive Mode.
150 Opening BINARY mode data connection for test2.sql
226 Transfer complete
23957080 bytes sent in 0.2 secs (1.2e+05 Kbytes/sec)

If large files are uploaded to FTP, then it would be a good idea to monitor the progress of the upload. For this you can use the commands hash And tick .

hash - the command after which ftp will print the “#” character every 1024 bytes of data:

ftp> hash
Hash mark printing on (1024 bytes/hash mark).
put file2.tar.gaz
##########################
226 Transfer complete
785888111 bytes sent in 6.94 secs (1.1e+05 Kbytes/sec)

tick - the command will display the byte counter:

ftp>tick
Hash mark printing off.
Tick ​​counter printing on (10240 bytes/tick increment).
ftp> put file2.tar.gz
local: file2.tar.gz remote: file2.tar.gz
227 Entering Passive Mode.
150 Opening BINARY mode data connection for file2.tar.gz
Bytes transferred: 912706618 -> counter
226 Transfer complete
912706618 bytes sent in 8.08 secs (1.1e+05 Kbytes/sec)

That's all basic set commands for working with ftp in the console. To view the list of available commands on a given FTP server, you can use the command help :

ftp>help
Commands may be abbreviated. Commands are:

Debug mdir sendport site
$ dir mget put size
account disconnect mkdir pwd status
append exit mls quit struct
ascii form mode quote system
bell get modtime recv sunique
binary glob mput reget tenex
bye hash newer rstatus tick
case help nmap rhelp trace
cd idle nlist rename type
cdup image ntrans reset user
chmod lcd open restart umask
close ls prompt rmdir verbose
cr macdef passive runique ?
delete mdelete proxy send

You can also get short help for each command. help<команда> :

ftp>help status
status show current status

ftp>help quit
quit terminate ftp session and exit

ftp>help bye
bye terminate ftp session and exit

And finally, the two teams above quit or bye to close the ftp session and exit:

ftp> quit
221 Goodbye.

Detailed information with descriptions of commands can be obtained using man ftp on the command line.

# man ftp
Formatting page, please wait...
FTP(1) BSD General Commands Manual FTP(1)

NAME
ftp - Internet file transfer program

SYNOPSIS
ftp [-Apinegvd]
pftp [-Apinegvd]
................
...............

And I thought: does everyone know that standard Windows tools are quite enough to work with FTP storages? In this article I will describe three simple methods transferring files via FTP using an example. The same techniques apply in . All you need is , Explorer and the command line.

Method one: Internet Explorer 8

Any Internet user is familiar with HTTP addresses for accessing websites that are entered into address bar browser - for example, . Addresses for accessing FTP servers are built according to the same principle: .

Enter your public FTP storage address, such as Microsoft (Figure A), in the address bar and click . If the connection is successful, you will see the root directory. To access subdirectories and files, click on the main directory. To download a file, click on it right click mouse and select the “Save Target As” option.

As you can see, all database articles, patches, updates, utilities and Microsoft documentation are stored on the server, only they are presented in the form of a list with dates. Detailed information about FTP storage is contained in the "readme.txt" files.

Figure A. Microsoft FTP server as seen from Internet Explorer 8.

Please note: to successfully connect to an FTP server using IE, the “Enable FTP folder view (outside of Internet Explorer)” and “Use passive FTP protocol ( Use Passive FTP (for firewall and DSL modem compatibility) in the Browsing section of the Advanced tab of the Internet Options dialog box. You can call it from the “Tools” menu.

To access private FTP servers, you must enter a username and password (Figure B). However, this way in IE 7 or IE 8 you can only view a list of files. To download you will have to use Explorer ( Windows Explorer). See Fig. for details. C, D, E and F.


Figure B: A username and password are required to access private FTP servers.


Figure C. Select the “Page | Open FTP site in Windows Explorer"(Page | Open FTP Site in Windows Explorer) or "View | Open FTP Site in Windows Explorer (View | Open FTP Site in Windows Explorer) to launch Explorer.



Figure D: In the Internet Explorer Security Warning dialog box, click Allow.

FTP is an important TCP/IP utility for transferring files between systems. One of the main advantages of FTP is its compatibility with many different remote host systems: files can be transferred between remote Windows 2000, Windows NT and UNIX systems, and even IBM servers such as AS/400. To launch the FTP utility, which has a text interface and comes with Windows 2000 and NT, simply enter ftp at the command line.

Let's list the 10 most useful commands FTP.

10. Help (or?). Many FTP commands can be entered in different ways. For example, Help and a question mark (?) perform the same function. Beginners should start with the Help command, after entering which the system provides the user with full list FTP commands. To get brief description commands to be entered? and then the command name:

Ftp>? open

9. Open. An FTP session typically begins with an Open command, which establishes a connection to the specified FTP server (the remote host must have an FTP service running). After receiving the Open command, the system requests a user ID and password. Many FTP servers allow you to register with an anonymous ID and a blank password. To establish a connection with a computer named teca2, you need to enter

Ftp>open teca2

8. Quit (or Bye). The Quit command ends any open session and exits the FTP shell:

Ftp>quit

To close an open session without terminating FTP, use the Close command.

7. Pwd. The Pwd command displays the directory on the remote machine with which at the moment connection established within an FTP session:

6. Ls. The Ls command shows a list of files and subdirectories located in the current directory on remote computer. Ls allows you to access remote files:

5. Cd. If the desired file is not in the current directory of the remote system, you can use the Cd command to change to another directory. If a connection is established to a UNIX machine, the remote directory is usually indicated by a forward slash (in this case the /downloads directory):

Ftp>cd/downloads

4. Lcd. The Lcd command changes the current directory on the local machine. Any files received from the remote machine will be written to the current directory by default. To change the current local directory to C: emp, you should enter the command

Ftp>lcd C: emp

3. Bin (or Binary). By default, FTP transfers files in ASCII format, which is convenient for text files. But to transfer executable and .zip files, you need to change the transfer type to binary using the Bin command:

To return to ASCII mode, use the ASCII command.

2. Put (or Send). The Put command allows you to copy local file to the current directory of the remote machine. To send a file named localfile.txt to the C: emp directory on the remote system, you need to enter the command

Ftp>put C: emp localfile.txt

1. Get (or Recv). The Get command is used to download files from the Internet (or from remote machines) to the current directory of the local machine. To get a file named remotefile.txt, you would enter the command

Ftp>get remotefile.txt

Michael Auty is the scientific editor of the American Windows NT Magazine, president of TECA, a company specializing in the development of software and provision of consulting services. He can be contacted at:

Share