Basic FTP commands in Linux. How to download files from FTP from the Windows command line Install msp from the command line download ftp

FTP is one of the common network protocols used by Internet users. The overwhelming majority of people use various FTP clients to download something from FTP servers. But not many people know that in Windows, the ability to connect to FTP servers from the command line is available.

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

To download file from FTP from Windows command line, let's do a few simple steps:

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

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

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

There are various ways to connect to an FTP server using a graphical environment, but the sysadmin needs to know the power of the 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. Connecting to an FTP server using the command line

A terminal is used to connect to any server using the command line.

$ ftp ftp. site

2. Upload the file to the FTP server

To upload the file to the server use FTP put. First, you need to go to the correct folder on the FTP server to download 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 upload one file. To download any file from the FTP server, first log into 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. First, 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 / home / captain directory for uploaded files on 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.

!
Quit the shell

?
Print help about local information

append
Add to file

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

bell
Beep on command completion.

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

bye

cd
Change remote working directory (use ".." to go to parent).

close
End FTP session.

delete
Delete deleted file.

debug
Toggle debug mode.

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

disconnect
End FTP session.

get
Get file (see also mget).

glob
Toggle extension metacharacter from local filenames.

hash
Toggle printing '#' for each buffer passed.

help
Show a list of commands.

lcd
Change local working directory.

literal
Send an arbitrary FTP command.

ls
Show the contents of the 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
Remote FTP connection.

prompt
Rough interactive prompt on multiple teams (this is toggle)

put
Send one file (see also mput).

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

quit
End connection session and work.

quote
Send an arbitrary 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 state.

trace
Toggle packet tracing.

type
Set Transfer File Type

user
Submit new user information.

verbose
Switch verbose mode.

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

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 link 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> You can specify the name of the machine you want to contact, although this is optional. The following example shows how the hostname ftp.botik.ru is written: $ ftp ftp.botik.ru This is equivalent to using the ftp open command to connect to the host 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 topic, 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 appear 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 the use of 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.
-dMakes ftp 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 will need to 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 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 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 the connection to the remote machine ftp.botik.ru to be opened. $ 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 will automatically connect 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 disallow 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 on to the admin machine, and open is the password for guido.

Restriction for ftp commands.
There are several advanced commands that provide additional convenience to the user. But not all ftp servers understand them. The commands, the use of which will be described 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. Depending on which mode is set: 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 full 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. A more advanced version was installed. I don’t know how she is advanced, but she doesn’t 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 return to the same state they were before this command was issued. If a shell command is typed 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 causes 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> append local_file_name_file_name of the remote_machine You can also use just the command name and then ask for the filename, for example: ftp> 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 a beep on your terminal after each file transfer is complete. To stop beeping, you need to 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> 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> cd (remote-directory) / usr / bin
closeThis command closes the current connection. However, ftp does not exit. You can create another link.
debugThis 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.
verboseThis 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> delete filename to delete 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> delete (remote-file) file name to delete
dirThis 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> 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 output 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 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> 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> 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> 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> get (remote-file) filename of the remote machine (local-file) filename of your machine
globThis command causes ftp to 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 the files.
hashThis command causes ftp to display a "#" character after every 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.
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, 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> 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 that 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 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> 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> 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> 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> 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> mdir name_1 of_remote_machine_file ... printfile Note that the last name is the name of a file in your directory. It's possible to just use the command name. The ftp program will then ask you for the name of the files, for example: ftp> mdir (remote-files) name_1 of_remote_machine_file ... printfile local-file printfile? y
mgetThis command copies 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> mget file_name_remote_machine_name_2file ... If you did not specify file names when calling the command, the ftp program will ask you for them: ftp> mget (remote-files) name_of_remote_machine_file_2file_name ...
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> 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 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> mls name_1 of the_remote_machine_file ... printfile You can omit the names when calling the command, and then the program will ask you about them: ftp> 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. Of course, you must 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> mput 1your_directory_file 2your_machine_file ... If you have not specified names, the ftp program will ask you about it: ftp> 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> 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 invoking 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 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 file name of your machine and the file name of the remote machine when you issue the ftp command, for example: ftp> put your_file_name_file_name of the remote_machine or ftp> 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), then the program will ask you about them, for example: ftp> 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.
byeThe command is similar to the quit command mentioned above.
quoteThe command makes ftp send the parameters that 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> quote NLST If you specified only the 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 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 filenames, for example: ftp> rename old_file_name new_file_name If you used only the command name, ftp will ask for filenames: 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 removes a directory on the remote machine that you are currently linked to. You can specify the name of the directory to be removed when invoking the command, for example: ftp> rmdir / u / mydir or you can omit the name when invoking 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, you must have write permission on the remote machine to execute it.
sendThis command is similar to the put command described above.
sendportThis 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 called, the default is a specific port. This command should be used at the advice of your system administrator. As a rule, you only need it 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.
typeThis 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 some systems only. You can enter all of this information when invoking the user command, for example: ftp> 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> 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 causes ftp to 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 THERE to HERE. A file named passwd is created on machine HERE 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 provided. After the transfer is complete, 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> 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 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 the 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 (-> 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 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 file 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> 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 $

FTP (File Transfer Protocol) is a popular network protocol 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, dating back to 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 openly 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 give a 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 the FTP connection, just enter the command ftp<сервер> For example:

ftp test.hostingthutor.com

After pressing the enter key, 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> 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 being 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>

From the message, you can see 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 to transfer only text files. You can enter commands ascii or binary to switch between transmission modes. Binary mode must be used for all non-text file types - images, archives, programs, etc.

So, let's move on to the commands for navigating and navigating 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<имядиректории> - the command to go to the desired directory:

ftp> cd www
250 CWD command successful

Checking with the team pwd :

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

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

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

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

ftp> rmdir tmp
250 RMD command successful

Deleting files on 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 the 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 files from the remote ftp server 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 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 file to ftp server

put<имяфайла> - command for uploading one file to 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)

The download of each file 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, 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> hash
Hash mark printing on (1024 bytes / hash mark).
put file2.tar.gaz
##########################
226 Transfer complete
785888111 bytes sent in 6.94 secs (1.1e + 05 Kbytes / sec)

tick - the command will display the byte counter:

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

That's all the basic set of commands for working with ftp in the console. To view a 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

Also, you can get a 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 that are higher quit or bye to close ftp session and exit:

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

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

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

In order to master the windows FTP client and start working with it, let's try to connect to any FTP server in the 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 placing archives on FTP, without hesitation, we call it backup (the folder is created by the mkdir command). Now go to the directory we created with the following command: cd back-up. At the next stage, copy the file to the server, for which you need to set 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.

To make our FTP client do everything automatically, without asking questions, let's 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 to the startup line), containing a number of commands for the FTP client that will be automatically executed when the FTP client is launched from command line.

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

As a result, you should get 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