Basic FTP commands in Linux. How to download files from FTP from the Windows command line Initial command for a session with the ftp server

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 systems Windows 2000, Windows NT and UNIX, and even IBM servers, for example AS/400. To launch the FTP utility, which has a text interface and comes with Windows 2000 and NT, simply enter ftp at the command line.

Let's list the 10 most useful commands FTP.

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

Ftp>? open

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

Ftp>open teca2

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

Ftp>quit

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

7. Pwd. The Pwd command displays the directory on the remote machine with which this moment connection established within 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 desired file is not in the current directory of the remote system, you can use the Cd command to change to another directory. If a connection is established to a UNIX machine, the remote directory is usually indicated by a forward slash (in this case the /downloads directory):

Ftp>cd/downloads

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

Ftp>lcd C: emp

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

To return to ASCII mode, use the ASCII command.

2. Put (or Send). The Put command allows you to copy 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 - science editor of the American Windows log NT Magazine, President of TECA, a company specializing in software development and consulting services. He can be contacted at:

FTP (File Transfer Protocol) is the most popular protocol to transfer files (download and upload) from one system to another system. This provides a fast way to transfer files. There are many available applications on Linux and Windows such as VSFTPD, ProFTPD for Linux, FileZilla Server for windows and macOS.

Eat various ways I use a graphical environment to connect to the FTP server, but System Administrator must know the power command line. And in this topic “Download and upload files via FTP using the console” I will tell you how you can work with the command line to transfer/receive data.

1. Connect to an FTP server using the command line

To connect to any server using the command line, use the terminal.

$ ftp ftp.site

2. Upload file to FTP server

To upload a file to the server use FTP put. First, you need to go to the desired folder on the FTP server to upload the file and use the following command.

Ftp> cd uploads ftp> put /home/captain/my_file.txt

3. Download one file from FTP server

To download a file from an FTP server, we use the get command. Using this command we can download one file. To download any file from FTP server, first login to the FTP server, then go to the directory and use the following command to download any file:

Ftp> get my_file.txt

4. Upload multiple files to FTP server

To upload multiple files to an FTP server we use the MPUT command. We can specify a wildcard to upload multiple files to the server at the same time. Firstly, navigate to the desired folder on the FTP server to upload the file and use the following command. It will upload all files with .txt extension to the /home/captain directory for uploaded files on the FTP server.

Ftp> cd uploads ftp> lcd /home/captain/ ftp> put *.txt

5. Download multiple files from FTP server

To download multiple files from an FTP server, we use the MGET command. Using this command you can upload files.

Ftp> mget *.txt

Teams.

!
Exit shell

?
Print help about local information

append
Add to file

ascii
Set the transfer type to ASCII. Use this to transfer text files (HTM files).

bell
Sound signal when command completes.

binary
Set the transfer type to binary. Use this to transfer binary files(XE files and graphics).

bye

CD
Change remote working directory (use ".." to change to parent).

close
End the FTP session.

delete
Delete the deleted file.

debug
Switch debug mode.

dir
List (show) the contents of a remote directory.

disconnect
End the FTP session.

get
Get a file (see also mget).

glob
Switch extension metacharacter from local filename.

hash
Toggle printing '#' for each buffer passed.

help
Show a list of commands.

lcd
Change local working directory.

literal
Send a custom FTP command.

ls
Show the contents of a remote directory.

mdelete
Deleting multiple files.

mdir

mget
Get multiple files (see also get)

mkdir
Create a directory on the remote machine.

mls
List the contents of several remote directories.

mput
Send multiple files (see also put).

open
Connect to remote FTP.

prompt
Rough interactive prompt on multiple teams (this is a switch)

put
Send one file (see also mput).

pwd
Print working folder(where you are now) on a remote machine.

quit
End the connection session and work.

quote
Send a custom FTP command. You can view a list of raw FTP commands at www.nsftools.com/tips/RawFTP.htm

recv
Receive file

remotehelp
Get help from remote server

rename
Get file.

rmdir
Delete a directory on a remote machine.

send
Send one file.

status
Show current status.

trace
Toggle packet tracing.

type
Set transfer file type

user
Send new user information.

verbose
Toggle verbose mode.

The topic “Download and upload files via FTP using the console” is completed.

If the host you specified has an FTP server, it will ask you for a username and password. You can log in using your own username, if you have one, or you can log in as anonymous. Anonymous FTP sites are very often used as program archives. Once connected, you will receive an invitation ftp>. FTP uses separate commands, but they are similar to standard commands. The list of basic FTP commands is given in Table 4.3.

Notes

1 Help on commands can be obtained: about the utility ftp- on command ftph; about FTP commands - by command ftp>help or ftp> ?; about each FTP command - one command at a time ftp>helpcommand_name.

2 You can connect to an FTP server and exchange files in the Total Commander environment using the command Network - Connect withFTP-server... .

Table 4.3 – Basic FTP client commands

Usage

open sername

Opens a connection to the server. This name can be specified immediately when entering the ftp command that boots the client

ls or dir

Displays the contents of the server directory (remote computer)

CD dirname

Moves to another working directory (named dirname) on the server

put filename

Rewrites the file filename from the local computer to the server. The command is prohibited for anonymous users

get filename

Rewrites a file from the server to local computer

mput

Writes a group of files. Similar to the put command, but wildcards are allowed. Confirmation will be requested before each file is written.

mget

To cancel confirmations, enter prompt

Overwrites a group of files. Similar to the get command, but wildcards are allowed. Confirmation will be requested before each file is copied. # To cancel confirmations, enter prompt

Toggles symbol output

for each kilobyte transferred (buffer)

4.2.5.5 Logging out of the FTP client Closes the connection to this server and returns to command mode. This command is automatically executed when you exit the FTP client In order for a computer to find another on a network, there must be a mechanism for describing how to “get” from one computer to another. This mechanism for choosing the best path is called– hardware router or software for interfacing computer networks using different protocols). This pair indicates that if you are trying to connect to a destination address, you need to communicate through the network gateway.

Routing tables are an important part of the TCP/IP protocol in Windows, but the operating system does not show them to the average user. The utility is used to process network route tables route. To display the routing table (IP routing), you need to open a command prompt and enter the command routeprint(run without parameters, command route displays a certificate). But before looking at the routing table, it is advisable to enter the command on the command line ipconfig / all(or ipconfig - all), showing the installation of the TCP/IP protocol on the computer. You can also look at the TCP/IP section in the properties of the network adapter, but the first method is preferable (the data entered into the TCP/IP properties determines the protocol setting for the selected network, and the command ipconfig shows how Windows actually configured the protocol). If there are several network adapters, it is difficult to remember which settings apply to which adapter. The team ipconfig shows a list of different settings in an easy way readable format based on network adapter.

If you're having trouble getting packets through your network, it's best to start the diagnostic process by comparing the information provided by the command ipconfig, with information in routing tables. To understand the information contained in the tables, it is necessary to understand how the router works. Router or router (router) is a network device that, based on information about the network topology and certain rules, makes decisions about forwarding packets between different network segments (routers are one example of hardware network gateways). Network segment– a logically or physically separate part of the network (when dividing an IP-based network into logical segments, or logical subnets, each segment is allocated a range of addresses, which is specified by the network address and network mask; as a rule, the physical network segment is limited by the network device that provides connection of segment nodes to the rest of the network). The router's job is to route traffic (traffic) (flow of packets) from one network to another. Therefore, a router can consist of several network adapters, each of which is connected to a different network segment. Thus, a route is a sequence of routers through which a packet passes.

When a user sends a packet to a different network segment than the one the computer is connected to, the packet is forwarded to the router. The router then determines the segment to which the packet should be forwarded. It doesn't matter whether the router is connected to two network segments or ten. The router's decision making process is the same, and it is based on routing tables. The routing table is divided into five columns:

– “Network Destination” column – all network segments to which the router is connected are presented here;

– “Netmask” column – shows the subnet mask, but not network interface, to which the segment is connected, and the segment itself. This allows the router to determine the address class for the destination network;

– Gateway Address column – after the router has determined the destination network to which it needs to send the packet, it checks the gateway list. This list“tells” the router through which IP address the packet should be sent to the destination network;

– “Interface” column – provides information about the network adapter connected to the destination network. It would be more accurate to say that this column provides information about the IP address of the network adapter that connects the router to the destination network. But the router is smart enough to understand what the address is assigned to;

– “Metric” column – provides information about the metric (weight) of the route. The metrics of entries in the table play a role in calculating the shortest routes to various recipients. Metrics come into play when there are multiple routes for sending packets, i.e. in this case, Windows checks the metrics to determine the shortest path (if there is only one route to the destination, the metrics are not used).

There are many options for using the command route. Its syntax is as follows:

route [-f] [-p] [team [end_point] [mask netmask] [Gateway] [metric metrics]] [if interface]]

Parameter -f is optional. It instructs Windows to clear the routing tables of all entries that are not a host route (routes with a subnet mask of 255.255.255.255), a loopback network route (routes with an endpoint of 127.0.0.0 and a subnet mask of 255.0.0.0), or a multicast route broadcasts (routes with endpoint 224.0.0.0 and subnet mask 240.0.0.0). When this parameter is used in conjunction with one of the commands, the route table is cleared before the command is executed.

Parameter -R makes a certain route permanent. When using this option with the command add the specified route is added to the registry and used to initialize the IP routing table each time TCP/IP starts (by default, added routes are not saved when TCP/IP starts). When using the parameter with the command print– displays a list of permanent routes. All other commands ignore this parameter. Permanent routes are stored in the registry at HKEY_ LOCAL_ MACHINE\ SYSTEM\ CurrentControlSet\ Servi- ces\ Tcpip\ Parameters\ PersistentRoutes.

Team in syntax route may consist of four options: add– adding a route; change– changing an existing route; delete– deleting a route or routes and print– print the route or routes. You can use special characters in the command. If you need to print routes for the 192.x.x.x subnet, you can use the command routeprint 192.* .

End_point route can be a network IP address (where the host bits in network address have a value of 0), the IP address of the route to the host, or the value 0.0.0.0 for the default route.

Parametermask netmask specifies the network mask (also known as a subnet mask) according to the destination. The netmask can be a subnet mask corresponding to the network IP address, such as 255.255.255.255 for a route to a host, or 0.0.0.0 for a default route (the default route is used if none of the other routes are suitable). If this parameter is omitted, the subnet mask 255.255.255.255 is used. The endpoint cannot be more precise than the corresponding subnet mask. In other words, the value of bit 1 in the endpoint address is not possible if the value of the corresponding bit in the subnet mask is 0.

Gateway specifies the forwarding or next-hop IP address at which the set of addresses defined by the endpoint and subnet mask is available. For locally connected subnet routes, the gateway address is the IP address assigned to the interface that is connected to the subnet. For remote routes that are accessible through one or more routers, the gateway address is the directly accessible IP address of the nearest router.

Parametermmetric metrics specifies an integer route cost metric (ranging from 1 to 9999) that is used to select one of several routes in the routing table that most closely matches the destination address of the forwarded packet. The route with the lowest metric is selected. The metric reflects the number of transitions, the speed of the path, the reliability of the path, throughput ways and means of administration.

Parameterif interface indicates the index of the interface through which the destination is accessible, i.e. tells Windows which adapter to use. To display a list of interfaces and their corresponding indexes, use the command route print. Interface index values ​​can be either decimal or hexadecimal. Before hexadecimal numbers enter 0x. In case the parameter if omitted, the interface is determined from the gateway address.

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

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

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

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

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

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

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

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

It is often necessary to automate the processes of downloading, uploading and deleting files from an FTP server. For example, when working with distributed databases 1C data or to save 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 Exercise 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
Issue sound signal upon completion of the command

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 data block transferred.

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>]
Displays the abbreviated contents of the remote computer's directory, where:
<удаленный_каталог> — directory whose contents will be displayed; if not specified, the current directory is used;
<локальный_файл> — specifies a local file to save to the list; if not specified, the list is displayed on the screen.

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

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

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

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

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

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

prompt
Toggle interactive tooltip for compound commands.

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

pwd
Display the working directory of the remote computer.

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

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

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

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

rename <имя_файла> <новое_имя_файла>
Renaming 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 <имя_пользователя> [<пароль> ] [<учетная_запись> ]
Sending information to connect to remote computer, Where:
<Username> — username for connecting to the remote computer;
<password> - password for specified name user, if not specified but required for connection, the ftp command will prompt the user for it;
<Account> Account to connect to a remote computer, if not specified but required for connection, the ftp command will prompt 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 in this example The file name and directory are hardcoded in 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?