Open
Close

Basic FTP commands in Linux. Standard Windows utility "FTP client" from the command line (CMD) - for backing up or downloading files without your participation (automatically) Deleting files on an ftp server

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]
................
...............

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 FTP commands.

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 a complete list of FTP commands. To get a brief description of the command, enter ? 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 that is currently connected to in an FTP session:

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

5. Cd. If the file you need 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 a 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 and the president of TECA, a company specializing in software development and consulting services. He can be contacted at:

NAME
ftp - file transfer protocol

SYNTAX

Ftp [-v] [-d] [-i] [-n] [-U] [-p] [-g]

DESCRIPTION
The ftp program allows you to transfer files to or receive files from a remote computer, and works with files and directories on the remote computer.

WORKING WITH FTP.
To use the ftp program, you need to open a connection between your and the remote machine to or from where you want to move the file. This program allows you to have multiple links at the same time, although you can issue commands that affect only one link. Multi-machine communication allows you to communicate with multiple machines in a single ftp session. You do not need to register again on another machine when you want to change the communication machine. The link that is currently in use is called the current link.

Types of file recording for transfer to ftp.
The ftp program allows you to use two types of recording: ASCII or binary. Use ASCII for text files. Binary is used for binary data, which must be a contiguous sequence of bits. ASCII is set by default. The binary form can be used for some special files, such as programs, pictures, archives.

Call ftp.
To call ftp from a UNIX shell, enter the ftp command. When this command is completed, a prompt for this command will appear on your screen. It looks like this:

Ftp> You can specify the name of the machine you want to contact, although this is optional. The following example shows how to write the machine name ftp.botik.ru: $ ftp ftp.botik.ru This is equivalent to using the ftp open command to establish a connection with the machine you named. You can also call ftp without a machine name, for example: $ ftp If you did not set a machine name when calling ftp, you must open a connection to that machine in ftp. This is done using the ftp open command before you start transferring files. For more detailed information on this issue, see the section "Description of ftp commands" later in this chapter.

ftp options.
Additionally, when calling ftp, you can specify some options for this command. These options are placed after the ftp command name, but before the machine name, if specified. Each option consists of a hyphen (-) and one letter, for example: -v. Each option has a corresponding command of the same name that can be used within ftp. You should differentiate between the use of options and the corresponding ftp commands.

-vForces ftp to work in verbose mode. In this mode, ftp messages sent by the remote machine to ftp appear on your display screen. In addition, if you use this mode, a statistical message appears after each file transfer is completed. This mode is the default if ftp is running interactively. If ftp is running in command mode, verbose mode is disabled, then the -v option enables it. You can enable this mode inside ftp using the verbose command.
-dForces ftp to run in debug mode. In this mode, ftp messages sent by ftp to the remote machine are displayed on your display screen. If you do not use this option, the information is not displayed. You can also invoke this mode in ftp using the debug command.
-nPrevents the use of ftp auto-registration while communicating with a remote machine. When auto-registration mode is set, ftp automatically identifies you to the remote machine and registers you to that machine. (See "Using the .netrc File for Automatic Logging" later in this section.) If you use the -n option to disable automatic logging, you will have to use the user command to manually log in to the remote machine.
-gCauses UNIX filenames to be stripped of their extensions, such as the wildcard (*). If you do not use this option, ftp expands filenames with a universal extension in the file list. You can use the glob command instead of this option.
The following are examples of the use of ftp options: $ ftp -v -d ftp.botik.ru The above command calls ftp in verbose and debug mode and causes ftp to open a connection to a remote machine named ftp.botik.ru. In debug mode, commands sent to the remote machine are displayed on your screen. Verbose mode displays the recipient's responses and statistics about the bytes of information received. $ ftp -vd The above command calls ftp in verbose and debug mode, but does not open communications with the remote machine. $ ftp -ng ftp.botik.ru The above command calls ftp with the cancellation of auto-registration and the universal extension, and forces it to open a connection with the remote machine ftp.botik.ru. $ ftp -n -d The above command calls ftp with auto-registration and universal extension cancelled, without opening communication with any machine.

Using the .netrc file for automatic registration.
You can create a file called .netrc in your home directory as an added convenience. This file contains registration data strings for each machine that you need for automatic communication. When you call ftp by specifying a machine, that is, when you open a connection to the machine at the same time as the call, ftp reads the .netrc file. If there is an element string for that machine, then ftp automatically connects your machine to that remote machine. If you opened a connection in verbose mode, you will see how this happens. The file format consists of individual fields represented by key fields:

Machine name login name password password where machine, login, password are the keywords followed by the character data required for registration:

machineNode name.
loginUser name for registration.
passwordUser password for this node. The password is written in normal unencrypted text form. If you include your password in the .netrc file, then you must disable read/write access to that file for your group and all other users to prevent your password from being revealed. Otherwise ftp will not allow you to use this file. For more information on file permissions, see the documentation for the chmod command. There is some risk in writing your password to a file. You must weigh all safety conditions. Ask your administrator about any specifics before using this file.
If you do not enter a password into the file, ftp will ask you for it. Here is an example entry in the .netrc file: machine admin login guido password open where: admin is the host name, guido is the user who logs into the admin machine, open is the password for the guido user.

Limitation for ftp commands.
There are several extended commands that provide additional convenience to the user. But not all ftp servers understand them. The commands that will be used later in this chapter have certain limitations. The ftp program can provide a list of supported commands. To obtain such information, you need to use the command after establishing a connection with the remote machine.

Description of ftp commands.
When the ftp prompt appears on your screen, you can enter one of the commands described later in this section. After running the command, the ftp prompt will appear again. Depending on whether the mode is set to verbose or debug, additional messages may appear. After each command you need to press Enter. The command will not start executing until you press Enter. If you make a mistake while typing a command, you can use the BACKSPACE key to edit the text.

You do not need to enter the entire command name; you can enter a certain number of characters sufficient for identification. In most cases this is one or two characters away from the ftp command name. However, it is better not to be lazy and type in the commands completely. The fact is that the ftp client on the joker server can be changed by the system administrator. Not all clients understand short commands. For example, they could have been used before. But one fine day, the ftp program was replaced. We installed a more advanced version. I don’t know how advanced she is, but she doesn’t understand short commands.

! This command pauses ftp and calls the shell on the local machine. Any character(s) after the exclamation mark are treated and executed as shell commands. You can then return to ftp by exiting the shell. All ftp options and associated remote machines are returned to the same state as before this command was issued. If a shell command is typed on the same line as !, then only that command is executed. After executing the command, the ftp program returns to command mode.
appendThe append command causes ftp to append the contents of a local file to the end of the file on the remote machine you are currently connected to. When you call this command, you can specify which file to append to, for example: ftp> append local_file_name remote_machine_file_name You can also use just the command name and then be prompted for file names, for example: ftp> append (local-file) local_file_name ( remote-file) file_name of remote_machine
asciiThis command causes ftp to convert files to ASCII code. The default code is always ASCII.
bellThis command causes a signal to appear on your terminal after each file transfer is completed. To stop beeping, you need to type this ftp command again.
binaryThis command causes ftp to transfer the file in binary code.
quitThis command logs out of ftp. This command closes all open connections.
CDThis command replaces the directory name on the remote machine with a new one. You can write down the new name when you issue the command, as shown in the example: ftp> cd /usr/bin You can use only the ftp command name, then the machine will ask for the name of the new directory, for example: ftp> cd (remote-directory) /usr/ bin
closeThis command closes the current connection. However, ftp does not exit. You can create another connection.
debugThis command turns debug mode on and off. If the mode is turned on, a message appears on your display; when turned off, there are no messages.
verboseThis command turns verbose mode on and off. If the mode is turned on, a message appears on your display; when turned off, there are no messages.
deleteThis command deletes a file on the remote machine to which you are currently connected. You can specify the name of the file to be deleted when calling the ftp command: ftp> delete name of the file to delete If you prefer, you can omit the name when calling the ftp command. Then the machine will ask you for a name, for example: ftp> delete (remote-file) name of the file to delete
dirThis command will give you the directory table of contents on the remote machine you are connected to. You can specify the name of the directory to print when calling the ftp command. For example: ftp> dir /usr/bin If you do not specify a directory name, the current directory on the remote machine will be printed. You can also tell ftp to write the results of the command to a file before it appears on the screen. This is done as follows: ftp> dir /usr/bin printfile You must specify the directory name before the output file name (here printfile). So if you want to print the current directory to a file called printfile, do this: ftp> dir . printfile where "." means current directory.
getThis command copies a file from the remote machine you are currently connected to. This file is copied to your directory on the server. Use the mget command to copy multiple files at once. When you call this command, you can specify the name of the file on the remote machine and the name in your directory where you will copy the file. For example: ftp> get remote machine file name your machine file name If you simply specify the name of the remote machine file you want to copy, the file on your machine will have the same name. Example: ftp> get remote_machine_name You can only write the ftp get command. Then the ftp program will ask you for the file name, for example: ftp> get (remote-file) file name of the remote machine (local-file) file name of your machine
globThis command causes ftp to disallow UNIX filename extensions such as the universal "*". This command is used to both disable and enable the extension so that if it is given again, the extension will be enabled again. After allowing the extension, ftp will add an extension to all file names when displaying a list of files.
hashThis command causes ftp to display a "#" character after each block of data that is sent by the remote machine. The size of data blocks may vary depending on the software version. Today on the joker machine it is 1024 bytes. After entering this command, the current data block size will be printed. This command turns on or off the display of the "#" symbol when typing again. This way you can evaluate the file transfer speed.
helpThis command displays information about ftp operation. If you specify a command name after help, information about this command will appear. If you just type help, a list of ftp commands will appear.
lcdThis command changes the working directory used by ftp on your machine. You can specify the name of the directory you want as your working directory, for example: ftp> lcd /home/student/your_directory_name If you do not specify a directory name, the current directory will be used.
lsThis command prints an abbreviated list of the contents of the directory of the remote machine you are currently associated with. You can specify the name of the directory you want to print. For example: ftp> ls /usr/bin If you do not specify a name, the current directory will be printed. You can specify that the results of a command be written to a file before they appear on the display. This is done by specifying the name of the file on your machine where the directory listing should be placed, for example: ftp> ls /usr/bin printfile The directory name must be specified before the file is output (here printfile). For example, if you want to print the current directory to a file called printfile: ftp> ls . printfile where "." is placed to emphasize that the directory is current.
mdeleteThis command deletes a list of files on the remote machine you are currently connected to. You can specify file names to be deleted when calling the command. For example: ftp> mdelete remote machine filename1filename2... Otherwise, you can just use the command name. The ftp program will ask you for name(s): ftp> mdelete (remote-files) file_name1file_name2...
mdirThis command produces a directory listing of the remote machine and places the result in a file in your directory. You can specify a list of files on the remote machine and the name of the file on your machine where to place the result when calling the command. For example: ftp> mdir remote_machine_file_name... printfile Note that the last name is the name of the file in your directory. It is possible to simply use the command name. Then the ftp program will ask you for the names of the files, for example: ftp> mdir (remote-files) remote_machine_file_name... printfile local-file printfile? y
mgetThis command copies multiple files from the remote machine you are currently connected to into your directory. The files after copying will have the same names as on the remote machine. You can specify a list of files to copy: ftp> mget remote machine file name 1 file name 2 file... If you did not specify file names when calling the command, the ftp program will ask you for them: ftp> mget (remote-files) remote machine file name 1 file name 2 file...
mkdirThis command creates a directory on the remote machine you are currently connecting to. You can specify a directory name when calling the command, for example: ftp> mkdir /u/mydir If you do not specify a name, ftp will ask you for it, for example: ftp> mkdir (directory-name) directory_name Of course, you must have write permission on the remote machine.
mlsThis command gets an abbreviated list of a group of files in the current directory on the remote machine and puts the result into a file on your machine. You can specify a list of files on the remote machine and a file on your machine where to place the result when calling the command, for example: ftp> mls remote_machine_file_name... printfile You can omit the names when calling the command, and then the program will ask you for them: ftp> mls ( remote-files) remote_machine_file_name... printfile local-file printfile? y
mputThis command copies one or more files from your directory to the remote machine you are currently connected to. On the remote machine, the files will have the same names. Of course, you must have write access to the remote machine to run this command. You can specify a list of files when calling the command, for example: ftp> mput 1file_of_your_directory 2file_of_your_machine... If you did not specify names, the ftp program will ask you about it: ftp> mput (local-files) name_1of_your_directory_name_2file_name...
nmapUse this command to set or disable the filename resolution engine. This command is useful when communicating with UNIX-incompatible machines that use a different file naming method. For example, servers based on Apple Macintosh. Renaming files on a local machine is done using the get and mget commands, and on a remote machine using put and mput commands.
ntransUse this command to enable or disable the filename character translation mechanism. This command is useful when communicating with a non-UNIX-compatible remote machine that uses a different file naming method. For example, servers based on Apple Macintosh. Translation of file names on the local machine is done using the get and mget commands, and on the remote machine using the put and mput commands.
openThis command establishes a connection with a remote machine that is supposed to transfer files. When calling the command, you can specify the machine name, for example: ftp> open ftp.botik.ru If the name is not specified, the program will ask for it: ftp> open (to) machine name If you specified the machine name when calling the command, you can also specify the number port on the remote machine. If a port is specified, ftp will open communications on that port if it is preferred over the default. Port changes are made if you are instructed to do so or if the system administrator specifies it. If the port is not specified, the program does not request it.
promptThis command prevents you from asking ftp for permission to move between files in multi-file commands such as mget. This command is enabled and disabled when retyped.
putThis command moves a file from your machine to the remote machine you are currently connected to. To transfer multiple files at once, use the mput command. You can specify your machine's file name and the remote machine's file name when calling the ftp command, for example: ftp> put your_file_name remote_machine's_file_name or ftp> put your_file_name Of course, you must have write permission on the remote machine to run this command. If you do not specify the name of the file(s), the program will ask you for them, for example: ftp> put (local-file) your_file_name (remote-file) remote_machine_file_name If you do not specify the file_name of the remote machine, the put command will create the file on the remote machine machine under the same name as your machine.
pwdThis command displays the name of the current working directory on the remote machine you are currently connected to.
byeThe command is similar to the quit command discussed above.
quoteThe command causes ftp to send the parameters you enter into the machine to the remote machine for execution. Options are ftp commands and other options. Those commands that ftp supports can be displayed on the screen using the remotehelp command. You can enter this command when calling the ftp program, for example: ftp> quote NLST If you only specified a command name, ftp will ask you for the command line to use, for example: ftp> quote (command-line to send) NLST This command follows Use only on the advice of your system administrator.
recvThis command is similar to the get command described above.
remotehelpThis command requests ftp help on the remote machine you are currently connected to. This information tells you what commands the remote machine supports.
renameThis command renames a file on the remote machine you are currently connected to. When calling the command, you can use file names, for example: ftp> rename old_file_name new_file_name If you used only the command name, then ftp will ask for file names: ftp> rename (from-name) old_file_name (to-name) new_file_name Of course, to execute this command you must have write permission on the remote machine.
rmdirThis command deletes a directory on the remote machine you are currently connected to. You can specify the name of the directory to be removed when calling the command, for example: ftp> rmdir /u/mydir, or you can leave the name out when calling the command and the machine will ask you for it: ftp> rmdir (directory-name) /u /mydir This command is not always supported by the remote machine. Of course, to do this you must have write access to the remote machine.
sendThis command is similar to the put command described above.
sendportThis command causes ftp to disable the ability to set the local machine's port for remote machine data. This command can be enabled and disabled by typing it again. When calling ftp, a specific port is specified by default. This command should be used as advised by your system administrator. As a rule, it is only needed when working with some “wrong” ftp server that is incompatible with your client program.
statusThis command causes ftp to display its current status on your terminal. The status includes modes that are selected by the bell, hash, glob, port, type commands.
typeThis command sets in what form the file is transferred. ASCII and binary codes are accepted. This command is similar to the ascii and binary commands. If you do not specify a type when calling the command, ASCII is set.
userThis command allows you to identify yourself to the remote machine when establishing a connection. This auto-registration is enabled with the -n option when calling ftp. In this case, this command is not needed. If automatic registration is disabled, then use this command to register and identify yourself on the remote machine. The remote machine needs to be told three pieces of information about who you are: login name, password, and resource name. The username is required for all machines, the password and resource name are required only for some systems. You can enter all of this information when calling the user command, for example: ftp> user mike cat myaccount You can choose not to provide all of this information when calling the command. Then the program will ask you about it, for example: ftp> user (usename) mike(username) password: Account: myaccount(resource name) Note that your password is not displayed when you type it to protect your information. If you do not enter a password or resource name, you will not be prompted for them.
verboseThis command causes ftp to disable verbose mode. This command is toggled on and off when redialed. In verbose ftp mode, protocol messages sent by the remote machine appear on your terminal. In addition, this mode displays statistics after each file transfer. If this mode is disabled, then this information is not displayed.
? Another name for the help command.

Examples of ftp operation.
This section illustrates how ftp can be used. Below are three examples. These examples use two machines, a local machine named HERE and a remote machine named THERE.

Description of 1 example.
This example shows the use of ftp to send and receive files. The ftp command is called with the name of the host machine and the user is automatically registered on another machine, because The -n option is not used.

Verbose mode is disabled using the verbose command. The user then changes the working directory on the remote machine to the /etc directory. Because there is no -d option and there is a verbose command, verbose mode is disabled and no messages other than the ftp prompt appear.

The user, using the ls command, receives an abbreviated listing of the /etc directory of the machine THERE. the ftp command produces three files in the /etc directory. The get passwd command then copies the passwd file from the THERE machine to the HERE machine. A file called passwd is created on the HERE machine if a machine name was specified.

The put command is used to copy a file named wall from the local machine's current working directory (HERE) to the remote machine's /etc directory (THERE). This file is copied with the same name because its name was not specified. After the transfer is completed, the /etc listing appears, in which there are already four files, including wall, which was just copied from the HERE machine.

The bye command is then used to return to the operating system shell on the local HERE machine.

$ ftp THERE Connected to THERE 220 THERE FTP server (Version 4.160 #1) ready Name (THERE:stevea): Password (THERE:stevea): 331 Password required for stevea. 230 User stevea logged in. ftp> verbose Verbose mode off. ftp> cd /etc ftp> ls passwd volcopy whodo ftp> get paswd ftp>put wall ftp> ls passwd volcopy wall whodo ftp> bye $ Description 2 examples.
This example illustrates the screen images that can be obtained using several ftp options. After calling ftp with the name of the remote host machine, the user calls a command that will return to debug mode. After this, the ftp command displays messages on the screen indicating that this option is enabled. The user then changes the working directory on the remote machine to /etc. Because There are debugging and verbose modes; messages about sending commands to the remote machine (--> CWD/etc) and responses received from the remote machine (250 CWD command successful - the command was successful) will appear on the screen. Note that the cd command, which has the same form as the change directory command in UNIX, is sent as a CDW (change working directory on the remote machine) command. This command is used by ftp instead of cd so that it works independently of the system command.

Following the cd command, the user issues a pwd command to confirm the change to the working directory. The ftp commands will display on your screen the messages sent between your (local) machine and the remote machine, and then the current working directory on the remote machine will appear. Then the user types the hash option, to which a message appears that this option is allowed. The get wall myfile command tells ftp to restore the wall file and place it in the file myfile in the current working directory on your machine. The ftp command will print messages sent between the local and remote machines about the start of the transfer and then print a hash tag for each block of information received. Once the transfer is complete, statistics appear on the screen showing the time it took to transfer and the date the file was transferred. After receiving the file, the user closes the connection with the close command and exits ftp with the bye command.

$ ftp THERE Connected to THERE 220 THERE FTP server (Version 4.160 #1) ready Name (THERE:stevea): Password (THERE:stevea): 331 Password required for stevea. ftp> debug Debugging on (debug = 1) ftp> cd /etc ---> CDW /etc 200 CDW command okay. ftp> pwd ---> PWD 251 ftp> hash Hash mark printing on (1024 bytes/hash mark). ftp> get wall mefile ---> PORT 3,20,0,2,4,51 200 PORT command okay. ---> RETR wall 150 Opening data connection for wall (3.20.0.2.1075)(24384bytes #######################. 226 Transfer complete. 24550 bytes received in 12.00 seconds (2 Kbytes/s) ftp> close ---> QUIT 221 Goodbye ftp> bye $

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
Displays 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?

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.