The standard Windows utility "FTP-client" from the command line (CMD) - for backing up or downloading files without your participation (automatically). Download, upload and delete files from an FTP server from the command line Batch file download from ftp

It is often necessary to automate the process of downloading, uploading and deleting files from an FTP server. For example, when working with distributed 1C databases or to save backups. 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 give the syntax of commands for working with FTP, as well as examples of bat-files for these operations.

1. ftp command

The ftp command is used to exchange files with an FTP server, here is its syntax:

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

-v Disable the display of responses from the remote server.
-n Disable automatic login on initial connection.
-i Disable interactive requests when passing multiple
files.
-d Enabling debug mode.
-g Disable globalization of filenames (see GLOB command).
-s: filename Specifies 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 login to the service.
-x: send sockbuf Overriding the default SO_SNDBUF buffer size (8192).
-r: recv sockbuf Overriding the default SO_RCVBUF buffer size (8192).
-b: async count Overriding the default async counter size (3)
-w: windowsize Override the default transmit buffer size (65535).
knot Setting the name or IP address of the remote host,
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, this command only starts an ftp session:

!
Temporary transition to the shell.

append
Adding to file.

ascii
Set the ascii file transfer mode.

bell
Beep on command completion

binary
Sets the file transfer mode in binary format.

bye
End ftp session and exit.

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

close
Ending ftp session.

debug
Switch debug mode.

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

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

disconnect
Ending ftp session.

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

glob
Switching the metacharacter extension of local file names.

hash
Toggle the "#" output for each data block transmitted.

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

lcd [ <локальный_каталог> ]
Change 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\u003e] [<local_file\u003e]
Displays the abbreviated contents of the remote computer directory, where:
<удаленный_каталог> - directory, the contents of which will be displayed; if not specified, the current directory is used;
<локальный_файл> - specifies the local file to be saved to the list, if not specified, the list is displayed on the screen.

mdelete<remote_file_1> … <remote_file_n>
Delete multiple files on a remote computer, where:
<удаленный_файл_n> - the names of the files to be deleted.

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

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

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

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

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

prompt
Toggle interactive prompt for compound commands.

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

pwd
Lists the working directory of the remote computer.

quit
Exit ftp session and exit to command line.

quote <команда>
Sending 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> - the name of the file on the local computer .

remotehelp [ <команда> ]
Get help information about commands on a remote system, where:
<team\u003e - command of the remote system, if not specified, then a list of all commands is displayed.

rename <имя_файла> <новое_имя_файла>
Renaming a deleted file, where:
<file name> - the name of the file to be renamed;
<new_file_name> - new file name.

rmdir <имя_каталога>
Removing a directory on a remote computer, where:
<directory_name> - the name of the directory to be deleted.

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

status
Reflects the current state of the ftp connection.

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 <имя_пользователя> [<пароль> ] [<учетная_запись> ]
Sending information to connect to a remote computer, where:
<username> - username to connect to a 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> - 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 display mode.


Let's look at a small example.

First, let's write a "batch file" that will upload to the server website file file_data.dat from " C: \\ example". The bat-file operation algorithm 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;
  • Remove 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 in such a way that it receives the data for loading as parameters, and also move all the changed values \u200b\u200binto the 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.

Similarly, you can write bat files for and on the FTP server, as well as an executable file with an arbitrary set of instructions.

Did this article help you?

To connect to the FTP server, you do not need to use any third-party programs - this can be done using standard Windows capabilities. To do this, you can use the command line CMD. But in order to control the server through the standard capabilities of the operating system, you will have to study the available commands, since CMD does not have a visual interface. In this article, you will learn the basic FTP commands and how to put them into practice.

Why download the client is better than using CMD

If the CMD command line allowed all available operations to be performed on FTP servers, then there might be no need for clients. But the reality is that the CMD line is quite limited in terms of server management. Therefore, it is still better to find an opportunity and download to your computer a utility for managing a server via FTP. For example, download the FileZilla client program to your PC - you can download it for free from the official website of the developers. It won't take long to install. And to connect to the server, you just need to enter your username, password and hostname in the required line. It is much more difficult to do this through CMD.

The particular downside of the CMD line is that you won't even be able to go into passive mode while on the server. And without this mode, you will not be able to exchange files with FTP servers that work through NAT.

In fact, this is a very big flaw in CMD. Therefore, accept the fact that the Windows command line is only suitable for manipulating within the file system without data exchange. Although for those who use an FTP server for routine, repetitive work, the command line may seem quite convenient. But it's better to try both the client and the CMD to make any conclusions.

What are the commands for managing FTP in the CMD command line

First, run Command Prompt. This can be done by searching in the "Start" - find the file cmd.exe and open it, after which the line will be launched.

To connect to the server, you need to use the OPEN command. After this command, you need to enter the IP address or hostname with which you want to set up a connection. After entering this request, you will be able to log into the server. This can be done using the USER command, which makes a request for authentication through the entered login. Then you need to enter the PASS command, which means a password. When you enter your password and press Enter, you will be logged into the server.

In general, the command line is only suitable for "surfing" the server, moving files, etc. First, you will need to see the files that are on the server. To do this, use the LS command. Since there is no cursor on the command line, you need to select a directory or file using special commands. Use the CD or LCD line for this - the first is needed to change the current object on the remote computer, and the second is for the local one, that is, for your PC.

Although you will not be able to upload your files to an FTP server via CMD, it is possible to download data to your computer. To do this, use the GET command. First, write the GET command with the file name, and then specify which directory on your computer is the current one, so that the server will transfer the data to that folder.

These commands are used most often. That is, most users control the server through CMD in order to quickly download files without installing the client first. But you can go much further and use other commands on the server with the CMD line. For example, you can add a command completion signal to the server using the string BELL.

If you want to end the session and exit the command line and server, then write BYE. And to terminate the control connection only on the server, so that you remain inside the command line, write CLOSE. In this case, the files that you download to the PC from the server will continue to download and after the download is complete, the session will be completely closed.

With CMD you can easily manipulate directories on the server. For example, to delete a specified directory, use the DELETE command. And so that a list of files of a certain folder appears on the screen, write down the DIR and the path to the directory. If you want to delete more than one folder or file, but several at once, then use the MDELETE command, that is, multi-delete. Likewise, the "m" prefix can be used for other commands, so that you can combine multiple actions into one. So, to display a list of files of several directories at once, specify MDIR, and to download a batch of data from the server, use MGET. But do not confuse a multi-command with a single MKDIR - it is needed in order to generate a directory on the server.

There is a chance that your FTP server works without NAT technology, so the passive client mode is not needed. In this case, you will be able to upload certain files to the host. Use the MPUT command to upload multiple files, and PUT if you only want to upload one.

Another popular command that will most likely come in handy for you is RENAME. We need a command to rename files. It will be useful for those who use the server as a repository for site data. You will also need the PWD command, which determines the current folder on the remote FTP server, not on your computer, as the LCD line does.

The commands provided are not a complete list of functions that you can use in FTP. There are other commands as well. And you can find out about them right on the command line if you enter the HELP request. After that, a reference appears with all the available CMD commands that can be used in FTP. Just keep in mind that at this moment you must be connected to the server, otherwise Windows will give you a different directory. And if you want to request help from the server itself, then register REMOTEHELP.

Of course, server command management is a stone age. Therefore, it is better not to waste time, download a normal FTP client to your computer and use the server to the maximum, and not partially. But practice on the CMD command line hasn't bothered anyone yet!

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 the Internet. FTP is one of the oldest application protocols, dating back long before HTTP, and even before TCP / IP, in 1971.

The FTP protocol is vulnerable, that is, FTP cannot encrypt its traffic, all transfers are clear text, so usernames, passwords, commands, and data can be read by anyone who can intercept the packet over the network. For secure data transfer, SFTP (Secure File Transfer Protocol) is used. Unlike standard FTP, it encrypts both commands and data, preventing passwords and confidential information from being transmitted over the network. SFTP is similar in functionality to FTP, but since it uses a different protocol, standard FTP clients cannot communicate with the SFTP server and vice versa. Next, we will consider the basic commands for working with an 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 a 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 a help and 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 a FTP connection, just enter the command ftp<сервер> eg:

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 launch ftp from the console and then connect to the ftp server using the command open:

ftp
ftp\u003e test.site

In addition, it is possible to connect via ip:

ftp 114.55.5.11

Or with such an appeal ftp This e-mail is protected from spambots. To view it, Java-script support must be enabled in your browser, that is:

ftp This e-mail is protected from spambots. To view it, Java-script support must be enabled in your browser.
230 User ftpuser logged in
Remote system type is UNIX.
Using binary mode to transfer files.
ftp\u003e

You can see from the message that a binary (binary) transfer type is used to transfer files. Binary file transfer mode is the transfer of files as they are stored on the FTP server. Ascii (text) mode is used for transferring 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 navigating through the ftp server directories:

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

ftp\u003e pwd
257 "/" is the current directory

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

ftp\u003e 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<имядиректории> - the command to go to the desired directory:

ftp\u003e cd www
250 CWD command successful

Checking with the team pwd :

ftp\u003e pwd
257 "/ www" is the current directory

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

ftp\u003e mkdir tmp
257 "/ tmp" - Directory successfully created

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

ftp\u003e rmdir tmp
250 RMD command successful

Deleting files on ftp server

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

ftp\u003e delete test1.sql
250 DELE command successful

Downloading files from ftp

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

ftp\u003e 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\u003e 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 files are copied from the remote ftp server to the current local directory. To change the current local directory, use the command lcd:

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

ftp\u003e lcd / root
Local directory now / root

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

ftp\u003e 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\u003e 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 file to ftp server

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

ftp\u003e 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\u003e 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)

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

Another command option mput :

ftp\u003e 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, it would be nice to watch the progress of the download. To do 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\u003e 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\u003e tick
Hash mark printing off.
Tick \u200b\u200bcounter printing on (10240 bytes / tick increment).
ftp\u003e 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 -\u003e counter
226 Transfer complete
912706618 bytes sent in 8.08 secs (1.1e + 05 Kbytes / sec)

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

ftp\u003e 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

Also, you can get a short help for each command help<команда> :

ftp\u003e help status
status show current status

ftp\u003e help quit
quit terminate ftp session and exit

ftp\u003e help bye
bye terminate ftp session and exit

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

ftp\u003e quit
221 Goodbye.

Detailed information with a description of commands can be obtained using man ftp at 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 enough to work with FTP-storages? In this article, I will describe three simple FTP file transfer methods with an example. The same techniques work 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 based on the same principle:.

Enter the address of a public FTP repository, for example, Microsoft (Figure A), in the address bar and click. If the connection is successful, you will see the root directory. Click on the main directory to access subdirectories and files. To download a file, right-click on it and select the Save Target As option.

As you can see, the server stores all the database articles, patches, updates, utilities and documentation from Microsoft, only they are presented as a list with dates. For details on the FTP storage, see the readme.txt files.

Figure A. Microsoft FTP Server as viewed from Internet Explorer 8.

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

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


Figure B. Accessing private FTP servers requires a username and password.


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 ”to launch Explorer.



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

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 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 machine and the remote machine where 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 only affect one link. Multi-host communication allows you to communicate with multiple machines in a single ftp session. You do not need to re-register on another car when you want to change the car for communication. 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 kinds of notation: ASCII or binary. Use ASCII for text files. Binary is used for binary data, which must be a continuous sequence of bits. ASCII is the default. Binary view can be used for some special files, such as programs, pictures, archives.

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

Ftp\u003e You can specify the name of the machine you want to contact, although this is optional. The following example shows how the machine name ftp.botik.ru is written: $ 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 invoke ftp without a hostname, for example: $ ftp If you did not set a hostname when invoking ftp, you must open a connection to that host in ftp. This is done using the ftp open command before you transfer files. For more information on this subject, see the section "Description of ftp Commands" later in this chapter.

Ftp options.
Additionally, when invoking ftp, you can specify some options for this command. These options are placed after the ftp command name, but before the hostname, 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 inside ftp. You should distinguish between using options and the corresponding ftp commands.

-vMakes ftp run 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 after the completion of the transfer of each file, a statistical message appears about this. This mode is set by default if ftp is run interactively. If ftp is run in command mode, verbose mode is off, then the -v option turns it on. You can enable this mode inside ftp with 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, no information is displayed. You can also invoke this mode in ftp using the debug command.
-nPrevents ftp from using auto-registration when communicating with a remote machine. When set to auto-registration mode, ftp will automatically identify you to the remote machine and register you with that machine. (See "Using the .netrc File for Automatic Registration" later in this section.) If you use the -n option to disable automatic registration, you must use the user command to manually register with the remote machine.
-gCauses UNIX file names to be stripped of their extensions, such as universal (*). If you do not use this option, ftp will expand filenames with a generic extension in the file list. The glob command can be used instead of this option.
The following are examples of using the ftp options: $ ftp -v -d ftp.botik.ru The above command invokes ftp in verbose and debug mode and prompts ftp to open a connection with 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 received bytes of information. $ ftp -vd The above command invokes ftp in verbose and debug mode, but does not open connections to the remote machine. $ ftp -ng ftp.botik.ru The above command invokes ftp with auto-registration and universal extension canceled, and forces to open connection with the remote machine ftp.botik.ru. $ ftp -n -d The above command invokes ftp, unregistering auto-registration and universal expansion, without opening a connection to 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 element lines for each machine that you need for automatic communication. When you call ftp with a host, that is, when you open a connection to the host at the same time as the call, ftp reads the .netrc file. If there is a line item for this machine, then ftp automatically connects your machine to this remote machine. If you open a connection in verbose mode, you will see how it happens. The file format consists of separate fields, represented by key fields:

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

machineHost name.
loginCustom name for registration.
passwordUser password for this node. The password is written in normal unencrypted text form. If you have included your password in the ..netrc file, then you must disable reading / writing of this file for your group and all other users to prevent your password from being exposed. Otherwise ftp will not let you use this file. For more information on file permissions, see the chmod command documentation. There is some risk in writing your password to a file. You must weigh all the security conditions. Ask your administrator for all the specifics before using this file.
If you do not enter a password in the file, ftp will ask you for it. Here is an example of an entry in the .netrc file: machine admin login guido password open where: admin is the hostname, guido is the user who logs into the admin machine, and open is the password for guido.

Restriction for ftp commands.
There are several advanced commands that provide additional user convenience. 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 communication with the remote machine.

Description of ftp commands.
When the ftp prompt appears on the screen, you can enter one of the commands described later in this section. After executing the command, the ftp prompt appears again. Additional messages may appear depending on which mode is set: verbose or debug. 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 from the ftp command name. However, it is better not to be lazy and to type 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, earlier they could be used. But one day, the ftp program was replaced. We put in a more advanced version. I don't know how she is advanced, but she does not understand short commands.

! This command pauses ftp and invokes the command language (shell) on the local machine. Any character (s) after the exclamation mark are interpreted 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 they were before this command was issued. If a shell command is printed on the same line as and! Then only that command is executed. After executing the command, the ftp program returns to command mode.
appendThe append command forces ftp to append the contents of the local file to the end of the file on the remote machine you are currently connected to. When you invoke this command, you can specify which file to add to which, for example: ftp\u003e append local_file_name_file_name of the remote_machine.You can also use just the command name and then get a prompt for the filename, for example: ftp\u003e append (local-file) local_file_name ( remote-file) remote_machine_filename
asciiThis command prompts ftp to convert files to ASCII code. By default, the code is always ASCII.
bellThis command causes your terminal to beep after each file transfer completes. To stop beeping, you must type this ftp command again.
binaryThis command prompts ftp to transfer the file in binary.
quitThis command exits ftp. This command closes all open links.
cdThis command replaces the directory name on the remote machine with the new one. You can write the new name when you invoke the command as shown in the example: ftp\u003e cd / usr / bin You can only use the ftp command name, then the machine will ask for the name of the new directory, for example: ftp\u003e cd (remote-directory) / usr / bin
closeThis command closes the current connection. However, ftp does not exit. You can create another link.
debug This command turns debug mode on and off. If the mode is turned on, then a message appears on your display, when you turn off there are no messages.
verbose This command toggles verbose mode on and off. If the mode is turned on, then a message appears on your display, when you turn 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 invoking the ftp command: ftp\u003e delete the name of the file to be deleted If you prefer, you can omit the name when invoking the ftp command. Then the machine will ask you for a name, for example: ftp\u003e delete (remote-file) file name to delete
dir This command will give you the table of contents of the directory on the remote machine to which you are connected. You can specify the name of the directory to be printed when invoking the ftp command. For example: ftp\u003e dir / usr / bin If you did not specify a directory name, the current directory on the remote machine will be printed. You can also prompt ftp to write the results of the command to a file before it appears on the screen. This is done as follows: ftp\u003e dir / usr / bin printfile You must specify the directory name before the name of the output file (here printfile). Thus, if you want to print the current directory to a file called printfile, do the following: ftp\u003e dir. printfile where "." means the current directory.
getThis command copies a file from the remote machine to which you are currently connected. This file is copied to your directory on the server. Use the mget command to copy multiple files at the same time. When you invoke 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\u003e get remote_machine_file_name_your_machine_file_name If you just specify the name of the remote machine file to be copied, the file on your machine will have the same name. Example: ftp\u003e get remote_machine_name You can only write the ftp get command. Then the ftp program will ask you for a filename, for example: ftp\u003e get (remote-file) filename of the remote machine (local-file) filename of your machine
globThis command makes ftp disallow the UNIX filename extension, such as the generic "*". This command serves to both disable and enable the extension so that if you re-enter it, the extension will be enabled again. After the ftp extension is resolved, it will add the extension to all filenames when listing files.
hashThis command causes ftp to display a "#" character after each block of data that is sent by the remote machine. The size of the data blocks may differ depending on the software version. As of today on the joker machine it is 1024 bytes. After entering this command, the current size of the data block will be printed. This command enables and disables the issuance of the "#" character on the screen when redialing it. This way you will be able to estimate the file transfer speed.
help This command displays information about ftp operation. If you specify a command name after help, information about that command will appear. If you just type help, you will see a list of ftp commands.
lcdThis command changes the working directory used by ftp on your machine. You can specify the name of the directory you want as a working directory, for example: ftp\u003e lcd / home / student / your_directory_name If you did not specify a directory name, the current directory will be used.
lsThis command prints out an abbreviated list of the directory contents of the remote machine you are currently connected to. You can specify the name of the directory you want to print. For example: ftp\u003e ls / usr / bin If you do not specify a name, the current directory will be printed. You can specify that the results of the command are placed in 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\u003e 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 named printfile: ftp\u003e ls. printfile where "." is used to emphasize that the directory is current.
mdeleteThis command removes the list of files on the remote machine you are currently connected to. You can specify filenames to delete when invoking the command. For example: ftp\u003e mdelete remote_machine_file_name1file_name ... Otherwise, you can just use the command name. The ftp program will ask you for the name (s): ftp\u003e mdelete (remote-files) filename1 filename filename2 ...
mdirThis command lists the directory listing of the remote machine and puts the result in a file in your directory. You can specify the list of files on the remote machine and the file name of your machine where to put the result when invoking the command. For example: ftp\u003e mdir name_1 of_remote_machine_file ... printfile Note that the last name is the name of a file in your directory. It is possible to just use the command name. The ftp program will then ask you for the name of the files, for example: ftp\u003e mdir (remote-files) name_1 of_remote_machine_file ... printfile local-file printfile? y
mgetThis command will copy multiple files from the remote machine you are currently connected to to 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\u003e mget file_name_remote_machine_name_2file ...
mkdirThis command creates a directory on the remote machine that you are currently connecting to. You can specify a directory name when invoking the command, for example: ftp\u003e mkdir / u / mydir If you do not specify a name, ftp will ask you for it, for example: ftp\u003e mkdir (directory-name) directory_name Of course, to run this command you must have the right to write on the remote machine.
mlsThis command gets an abbreviated list of the filegroup of the current directory on the remote machine and puts the result in a file on your machine. You can specify the list of files on the remote machine and the file of your machine, where to put the result when calling the command, for example: ftp\u003e mls name_1 of_remote_machine_file ... printfile You can omit the names when calling the command, and then the program will ask you about them: ftp\u003e mls ( remote-files) remote_machine_file1name ... 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. You must of course have write access to the remote machine to execute this command. You can specify a list of files when invoking the command, for example: ftp\u003e mput 1 your_directory_file 2your_machine_file ... If you have not specified names, the ftp program will ask you: ftp\u003e mput (local-files) your_directory_file_1_name_2file_name ...
nmapUse this command to install and remove the filename translation engine. This command is useful when communicating with UNIX-incompatible machines that use a different way of naming files. For example, servers based on Apple Macintosh. You can rename files on the local machine using the get and mget commands, and the remote machine using the put and mput commands.
ntransUse this command to enable or disable the character translation mechanism for the file name. This command is useful when communicating with a UNIX-incompatible remote machine that uses a different way of naming files. For example, servers based on Apple Macintosh. The names of the files of the local machine are translated using the get and mget commands, and the remote machine using the put and mput commands.
openThis command establishes communication with a remote machine that is supposed to transfer files. When calling the command, you can specify the machine name, for example: ftp\u003e open ftp.botik.ru If the name is not specified, the program will ask for it: ftp\u003e 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 communication on that port if it is preferred over the default. Port changes are made in the event that you piglets about it or it is set by the system administrator. If the port is not specified, then the program does not ask for it.
promptThis command prevents you from asking ftp for permission to navigate between files in multi-file commands such as mget. This command is enabled and disabled when redialing.
putThis command moves a file from your machine to the remote machine to which you are currently connected. Use the mput command to transfer multiple files at the same time. You can specify the filename of your machine and the filename of the remote machine when you issue the ftp command, for example: ftp\u003e put your_file_name_file_name of the remote_machine or ftp\u003e put your_file_name Of course, you must have write permission on the remote machine to execute this command. If you did not specify the name of the file (s), the program will ask you about them, for example: ftp\u003e put (local-file) your_file_name (remote-file) filename_remote_machine If you do not specify the file name of the remote machine, then the put command will create a file on the remote machine with the same name as your machine.
pwdThis command prints the name of the current working directory on the remote machine that you are currently connected to.
bye The command is similar to the quit command mentioned above.
quoteThe command makes ftp send the parameters you enter to the machine to send to the remote machine for execution. Parameters are ftp commands and other parameters. Commands that ftp supports can be displayed on the screen using the remotehelp command. You can enter this command when invoking the ftp program, for example: ftp\u003e quote NLST If you specified only the command name, ftp will ask you for the command line to use, for example: ftp\u003e 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.
remotehelp This command asks for 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\u003e rename old_file_name new_file_name If you used only the command name, ftp will ask for filenames: ftp\u003e 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 removes a directory on the remote machine that you are currently linked to. You can specify the name of the directory to be deleted when invoking the command, for example: ftp\u003e rmdir / u / mydir or you can omit the name when invoking the command and the machine will ask you for it: ftp\u003e rmdir (directory-name) / u / mydir This command is not always supported by the remote machine. Of course, you must have write permission on the remote machine to execute it.
sendThis command is similar to the put command described above.
sendport This command causes ftp to deny the ability to set the local machine port for remote machine data. This command can be connected and disconnected by redialing it. When ftp is invoked, it defaults to a specific port. This command should be used at the advice of your system administrator. Typically, it is only needed when working with some "wrong" ftp server that is incompatible with your client program.
statusThis command makes ftp display its current status on your terminal. The status includes the modes that are selected by the bell, hash, glob, port, type commands.
type This command sets how the file is transferred. ASCII and binary codes are accepted. This command is similar to the ascii and binary commands. If you did not specify the type when invoking the command, ASCII is set.
userThis command allows you to identify yourself to a remote machine when establishing a connection. This auto-registration is enabled with the -n option when invoking ftp. In this case, this command is not needed. If automatic registration is disabled, then use this command to register and authenticate yourself to the remote machine. The remote machine needs three kinds of information about who you are: login name, password, and resource name. A username is required for all machines, a password and resource name are required for only some systems. You can enter all of this information when invoking the user command, for example: ftp\u003e user mike cat myaccount You can omit all this information when invoking the command. Then the program will ask you about it, for example: ftp\u003e user (usename) mike (username) password: Account: myaccount (resource name) Note that your password is not displayed when typing it to protect your information. If you did not enter a password or resource name, then there will be no request for them.
verboseThis command makes ftp disable verbose mode. This command turns on and off when redialing. 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 command is help.

Examples of ftp.
This section illustrates how ftp can be used. Three examples are given below. 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, since 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 uses the ls command to get an abbreviated listing of the / etc directory of 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 named 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 current working directory of the local machine (HERE) to the / etc directory of the remote machine (THERE). This file is copied with the same name because no name was specified. After the transfer ends, the / etc listing appears, which already contains four files, including the wall that was just copied from the HERE machine.

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

$ 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\u003e verbose Verbose mode off. ftp\u003e cd / etc ftp\u003e ls passwd volcopy whodo ftp\u003e get paswd ftp\u003e put wall ftp\u003e ls passwd volcopy wall whodo ftp\u003e bye $ Description of 2 examples.
This example illustrates the screenshots that can be obtained using several ftp options. After calling ftp with the name of the remote host, the user invokes a command that will return debug mode. The ftp command then 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 debug and verbose modes, messages about sending commands to the remote machine (-\u003e CWD / etc) and responses received from the remote machine (250 CWD command successful) will appear on the screen. Note that the cd command, which has the same form as the UNIX change directory command, is sent as a CDW command (change the working directory on the remote machine). This command is used 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 in the working directory. The ftp commands will display on your screen messages being sent between your (local) and 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 myfile in the current working directory on your machine. The ftp command will print the 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. When 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\u003e debug Debugging on (debug \u003d 1) ftp\u003e cd / etc ---\u003e CDW / etc 200 CDW command okay. ftp\u003e pwd ---\u003e PWD 251 ftp\u003e hash Hash mark printing on (1024 bytes / hash mark). ftp\u003e get wall mefile ---\u003e PORT 3,20,0,2,4,51 200 PORT command okay. ---\u003e 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\u003e close ---\u003e QUIT 221 Goodbye. ftp\u003e bye $