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

FTP (File Transfer Protocol) is a popular network protocol that is used to copy files from one computer to another on a 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.

An FTP client is included with 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 transfer text files only. 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 (catalog):

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 the entire basic set of 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]
................
...............

Team FTP implements file exchange with an FTP server in the Windows command line. Utility ftp.exe is included in the standard distribution kit of all versions of operating systems of the Windows family and allows you to exchange with the server both in command and interactive mode.

Command line format:

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer] [-r:recvbuffer] [-b :asyncbuffers] [-w:windowsize] [node]

-v- Disable display of responses from a remote server.
-n- Disable automatic login upon initial connection.
-I- Disable interactive requests when transferring multiple files.
-d- Enable debug mode.
-g- Disable globalization of file names (see GLOB command).
-s:filename- Specify a text file containing FTP commands that will be executed automatically when FTP starts.
-a- Using the local interface to bind the connection.
-A- Anonymous connection to the server.
-x:send sockbuf- Override the default buffer size SO_SNDBUF (8192).
-r:recv sockbuf- Override the default buffer size SO_RCVBUF (8192).
-b:async count- Override default async counter size (3)
-w:windowsize- Override the default transmit buffer size (65535).
node- Specifying the name or IP address of the remote host to which you want to connect.

Notes:

The mget and mput commands accept the y/n/q parameters as YES/NO/QUIT.
- to stop executing commands, press the key combination CTRL+C.

When running without parameters, FTP goes into interactive mode, waiting for user input. A prompt appears on the screen - ftp >.

To get a list of available commands, you can enter a question mark or the command help

Command set:

!
?
append
ascii
bell
binary
bye
CD
close
literal
debug
dir
disconnect
get
glob
hash
help
lcd
ls
mdelete
mdir
mget
mkdir
mls
mput
open
prompt
send
put
pwd
quit
quote
recv
remotehelp
rename
rmdir
status
trace
type
user
verbose

You can get help for a specific command by entering a question mark or help and the command name:

? connect
help connect

List of Windows FTP client commands:

! - Temporary transition from the FTP environment to the Windows command line (CMD.EXE). To return to FTP use the command EXIT
append adding the data of the transferred file to the end of the existing one.
ascii- setting the file transfer mode in ascii format (text mode)
bell- issuing a sound signal upon completion of the command.
binary- setting the file transfer mode in binary format
bye- end the FTP session and exit the program.
CD- changing the current directory on the remote computer
close- ending the FTP session (closing the connection opened by the command open)
delete- deleting the specified file on the remote computer
debug- switch to debug mode
dir
disconnect- ending the ftp session. Disconnecting from the FTP server without ending the program.
get- receiving a file from an FTP server
glob- Switching the metacharacter extension of local file names. By default, this mode is enabled and allows you to use symbols * And ? in filename patterns.
hash- switching the hash mark output mode for each transferred buffer
help- output of help information on FTP commands
lcd- change the working directory of the local computer
literal- sending an arbitrary string of characters as an ftp command
ls- output the contents of the directory of the remote computer
mdelete- deleting multiple files
mdir- output the contents of several FTP server directories
mget- receiving multiple files from an FTP server
mkdir- creating a directory on the FTP server
mls- output the contents of several directories on a remote computer
mput- sending multiple files to an FTP server open- open a connection (connect) to the FTP server
prompt- changing the line prompt for entering commands in interactive mode.
put- transfer one file
pwd- display the name of the current working directory on the FTP server
quit- end the session and exit the program
quote- sending an arbitrary command to the FTP server
recv- receiving a single file
remotehelp- receiving help from the FTP server
rename- renaming the file
rmdir- deleting a directory on the server
send- single file transfer
status- display of the current session state - which server is connected to, the type of data transferred, the state of modes changed by FTP commands
trace- switching tracing mode
type- setting the file transfer type
user- changing the username in an exchange session with an FTP server
verbose- switching the detail mode when displaying messages

As can be seen from the list of commands listed, the standard FTP client in Windows operating systems does not support a complete list of standard FTP commands and, what is most unpleasant, it does not support the command to switch to passive mode ( passv) exchange with an FTP server, which makes it unsuitable for exchanging data with FTP servers connected to using network address translation technology NAT. In other words, a standard FTP client is not suitable for exchanging files with servers external to the client’s subnet. This applies to all versions of Windows, including Windows 10. It is this fact that determines the scope of use of the ftp.exe utility - only on local networks where a direct TCP connection between the client and server is possible.

Example session using a Windows FTP client:

open 192.168.1.1- open a connection to server 192.168.1.1
user admin- use username admin when connecting to the server. In response to this command, the server will ask for a password.
adminpass- enter a password for the user admin
ls- display a list of files and folders in a remote directory
get myfile.txt- accept file myfile.txt from the remote directory to the current local directory.
lcd C:\files- change the current local directory.
get myfile.txt- accept file myfile.txt from the remote directory to the current local directory (C:\files) .

When using the Windows FTP client in batch files, it is often used to run the program in the mode of managing FTP commands written to a text file.

ftp -s:ftpcomm.txt- A list of commands is written to the ftpcomm.txt file, in the same order in which they would be entered in interactive mode. For example, to receive the file binfile.bin in the C:\temp directory.

It is often necessary to automate the processes of downloading, uploading and deleting files from an FTP server. For example, when working with distributed 1C databases or for saving backup copies. But not everyone knows that these procedures can be performed from the command line without resorting to additional software, that is, Windows tools. Below I will provide the command syntax for working with FTP, as well as examples of bat files for these operations.

1.ftp command

To exchange files with an FTP server, use the ftp command, here is its syntax:

FTP[-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-A] [-x:sendbuffer]
[-r:recvbuffer] [-b:asyncbuffers] [-w:windowsize] [node]

-v Disable display of responses from a remote server.
-n Disable automatic login upon initial connection.
-i Disabling interactive requests when sending multiple
files.
-d Enable debug mode.
-g Disable file name globalization (see GLOB command).
-s:filename Specify a text file containing FTP commands that
will be executed automatically when you start FTP.
-a Using the local interface to bind the connection.
-A Anonymous login to the service.
-x:send sockbuf Override the default buffer size SO_SNDBUF (8192).
-r:recv sockbuf Override the default buffer size SO_RCVBUF (8192).
-b:async count Overriding the default async counter size (3)
-w:windowsize Override the default transmit buffer size (65535).
node Specifying the name or IP address of the remote node,
to which you want to connect.

As you can see, there are no operators for connecting to the server and working with files. The thing is that this command only starts the ftp session:

!
Temporary transition to the shell.

append
Adding to file.

ascii
Setting the transfer mode for files in ascii format.

bell
Sound signal when command completes

binary
Set the binary file transfer mode.

bye
End the ftp session and log out.

CD <удаленный_каталог>
Changing the working directory on the remote computer where:
<удаленный_каталог> — the name of the directory that will become working.

close
Ending the ftp session.

debug
Switching debugging mode.

delete <удаленный_файл>
Deleting a file on a remote computer where:
<удаленный_файл> — name of the file to be deleted.

dir [ <удаленный_каталог> ] [<локальный_файл> ]
Displays the contents of the remote computer's directory, where:
<удаленный_каталог>
<локальный_файл>

disconnect
Ending the ftp session.

get <удаленный_файл> [<локальный_файл> ]
Getting a file where:
<удаленный_файл>
<локальный_файл> — file name on local computer .

glob
Switching the metacharacter extension of local file names.

hash
Switches the "#" output for each transferred block of data.

help [ <команда> ]
Display help information for the ftp command, where:
<команда> — The command whose description will be displayed, if not specified, all commands will be output.

lcd [ <локальный_каталог> ]
Changing the local directory of the working computer, where:
<локальный_каталог> — The name of the new local directory; if not specified, the name of the current directory will be used.

literal <команда_1> … <команда_n>

<команда_n> — commands to send;

ls [<remote_directory>] [<local_file>]
Print the abbreviated contents of the directory of the remote computer, where:
<удаленный_каталог> — directory whose contents will be displayed; if not specified, the current directory is used;
<локальный_файл> — specifies a local file to save to the list; if not specified, the list is displayed on the screen.

mdelete<remote_file_1> … <remote_file_n>
Deleting multiple files on a remote computer where:
<удаленный_файл_n> — names of files to delete.

mdir<remote_directory_1> … <remote_directory_n> <local_file>
Print the contents of several directories on a remote computer, where:
<удаленный_каталог_n> — the directory whose contents will be displayed;
<локальный_файл> — specifies a local file to save to the list; if not specified, the list is displayed on the screen.

mget <удаленный_файл_1> <удаленный_файл_n>
Receiving multiple files where:
<удаленный_файл_n> — remote file to copy.

mkdir <удаленный_каталог>
Create a directory on the remote computer where:
<удаленный_каталог> — name of the remote directory to create.

mls<remote_directory_1> ... <remote_directory_n> <local_file>
Print the shortened contents of several directories on a remote computer, where:
<удаленный_каталог_n> — directory whose contents will be displayed; if not specified, the current directory is used;
<локальный_файл> — specifies a local file to save to the list.

mput <локальный_файл_1> … <локальный_файл_n>
Sending multiple files where:
<локальный_файл_n> — the name of the local files that will be copied.

prompt
Toggle interactive tooltip for compound commands.

put <локальный_файл> [<удаленный_файл> ]
Sending one file, where:
<local_file>
<удаленный_файл>

pwd
Display the working directory of the remote computer.

quit
End the ftp session and exit to the command line.

quote <команда>
Send an arbitrary ftp command, where:
<команда> — command to send.

recv <удаленный_файл> [<локальный_файл> ]
Retrieving a file using the current file type settings, where:
<удаленный_файл> — remote file for copying;
<local_file> — file name on the local computer .

remotehelp [ <команда> ]
Obtaining help information about commands on a remote system, where:
<team> — remote system command; if not specified, a list of all commands is displayed.

rename <имя_файла> <новое_имя_файла>
Renaming a remote file, where:
<file name> — file name to rename;
<new_file_name> — new file name.

rmdir <имя_каталога>
Deleting a directory on a remote computer where:
<directory_name> — name of the directory to delete.

send <локальный_файл> [<удаленный_файл> ]
Copy a single file using the current file type settings, where:
<local_file> — name of the local file to copy;
<удаленный_файл> — file name on the remote computer.

status
Displays the current ftp connection status.

trace
Toggle packet tracing.

type [ <имя_типа> ]
Setting the file transfer type, where:
<type_name> — file transfer type; if not specified, the current file transfer type will be displayed.

user <имя_пользователя> [<пароль> ] [<учетная_запись> ]
Send information to connect to a remote computer where:
<Username> — username for connecting to the remote computer;
<password> — password for the specified username, if not specified but required for connection, the ftp command will ask the user for it;
<Account> — an account for connecting to a remote computer, if not specified but required for connection, the ftp command will ask the user for it;

verbose
Switching the message output mode.


Let's look at a small example.

First, let’s write a “body file” that will upload to the server website file file_data.dat from " C:\example". The algorithm for the bat file will be as follows:

  • Create a transport.txt file with a sequence of ftp statements;
  • We execute the ftp command, specifying the created file as parameters;
  • Delete transport.txt.

In this example, the file name and directory are hardcoded into the file. This is not always convenient. Let’s modify the bat file so that it receives the data to be loaded as parameters, and we’ll also put all changeable values ​​into file variables. We get the following code ():

Accordingly, to copy the file file_data.dat from " C:\example" to the FTP server in " Temp\Backup", you will need to run this batch file, specifying the file name, local and remote directories as parameters.

In a similar way, you can write bat files for and on an FTP server, as well as an executable file with an arbitrary set of instructions.

Did this article help you?

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 for 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, which are entered into the address bar of the 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, right-click on it 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.

The FTP protocol is one of the common network protocols used by Internet users. The overwhelming majority of people use various FTP clients to download anything from FTP servers. But not many people know that Windows allows you to connect to FTP servers from the command line.

In this tip you will learn how download files from FTP servers using simple DOS commands.

In order to download file from FTP from Windows command line, let's perform a few simple steps:

  1. Open the Windows command prompt by clicking Start - Run, typing cmd and pressing Enter.
  2. Run the following command: Using this command, we will connect to the Microsoft ftp server.
  3. Enter the username anonymous. The server of this well-known company allows anonymous users to connect:
  4. Enter your e-mail as a password (you can enter a non-existent one):
  5. Congratulations on your successful login!
  6. In order to see what files and directories are available on the ftp server, enter the dir command:
  7. As a result, we get a list of files and directories located on the ftp server:
  8. To go to the required directory, use the cd command:
  9. The message "250 CWD command successeful" will indicate that we have successfully moved to the directory we need:
  10. In order to download the file we need, enter the get command and the name of the downloaded file:
  11. After successfully receiving the file, the system will notify us:
  12. To leave the ftp server and disconnect from it, run the bye command:

Perhaps many will say that it is much more convenient to download files using multifunctional download managers or ftp clients. But if necessary (or as an alternative), you can use simple DOS commands that will allow you download files from ftp at no additional cost.