Linux System FTP command

Source: Internet
Author: User
Tags aliases ftp site ftp client

Let's start with a simple FTP download script.

Ftp-i-n<<eof

Open 14.2.33.211

User ETL ETL

Cd/etlfile/ftpfile

Lcd/etlfile/getfile

Binary

Prompt

Mget *

Prompt

Close

Bye

Eof

FTP Installation section, the following steps:

You can install FTP directly using the Yum command

# yum Install vsftpd

The open and Close commands for the FTP service:

Open: # service VSFTPD start

Close: # service VSFTPD Stop

After successful installation, you can use the FTP software connection locally, the default account is the virtual machine's account number and password.

First installation, please restart the FTP service vsftpd Restart (if the firewall is not turned off, please turn off the firewall)

There are a lot of software about FTP (client, server build not speaking here), which is broadly divided into command line and GUI graphical interface.

1, the graphical interface has

Gftp

Gnome under FTP client

CrossFTP

Java-based stable FTP client and synchronization tool. Excellent Chinese/unicode support.

Kftpgrabber

KDE FTP client, support encoding selection. Good support for Chinese

FileZilla

Good support for Chinese

Krusader

FTP://IP can also be used via browser input

If you have a favorite can be installed through apt-get or aptitude.

2,CLI (command line) mainly has FTP and lftp

(1) FTP

1. Connect to the FTP server

Format: FTP [hostname| ip-address]

A) under Linux command line input: FTP 10.18.34.115

b) The server asks you for your username and password, enter yint and corresponding password separately, and wait for authentication to pass.

or use the following format

FTP--i-n IP_Address

User USERNAME PASSWORD

Like what:

Ftp-i-N 172.17.17.17

User PUB 123456

You can also write a script to log in automatically.

[Email protected]:~/desktop/shell$ cat ftp.sh

#!/bin/sh

Ftp-i-N 172.17.17.17

<<!

User PUB 123456

!

This will allow you to log in automatically.

2. Download the file

The download file usually uses the get and mget two commands.

a) Get

Format: Get [Remote-file] [Local-file]

Transfer files from the remote host to the local host.

To get E:/rose/1.bmp on the server,

Ftp> get/rose/1.bmp 1.bmp (return)

b) mget

Format: mget [Remote-files]

Receives a batch of files from the remote host to the local host.

To get all the files under e:/rose/on the server,

Ftp> Cd/rose

Ftp> mget * * (carriage return)

Note: The files are downloaded to the current directory of the Linux host. For example, the FTP command that runs under/root/yint, the files are downloaded to/root/yint.

3. Uploading Files

a) put

Format: Put Local-file [Remote-file]

Transfers a local file to the remote host.

If you want to transfer the local 1.bmp to the remote host E:/rose, and renamed to 333.bmp

Ftp> put 1.bmp/rose/333.bmp (carriage return)

b) mput

Format: Mput local-files

Transfers a batch of files from the local host to the remote host.

If you want to upload all BMP files in the local current directory to the server E:/rose

Ftp> cd/rose (carriage return)

Ftp> mput *.bmp (return)

Note: The upload file is from the current directory of the host. For example, the FTP command running under/root/yint will only be uploaded to the server e:/rose under/root/yint file Linux.

4. Disconnect the connection

Bye: Interrupts the connection to the server.

Ftp> Bye (carriage return)

(2) Lftp

When using LFTP to access some of the domestic FTP server, often see the Chinese is garbled, this is due to inconsistent server and local code.

Workaround:

Create a new file in the home directory ~/.LFTPRC or ~/.LFTP/RC

For example, I entered in the terminal:

Gedit ~/.LFTPRC #在当前目录下建立. lftprc file

Then enter the following in the dialog box that pops up:

Debug 3

Set Ftp:charset GBK

Set File:charset UTF-8

#set Ftp:passtive-mode No

#alias UTF8 "set Ftp:charset UTF-8"

#alias GBK "Set Ftp:charset GBK"

The above lines mean

To set the encoding for local and FTP servers

Alias is a command that uses aliases

If you have a friend who often uses a different encoding of FTP server, or if you often use different options, you can set some aliases, which is a lot easier.
Like what:

I often access GBK encoded FTP, and UTF8 encoded, so I wrote in ~/.lftp

Code:

Alias GBK set Ftp:charset GBK; Set File:charset UTF-8
Alias UTF8 set Ftp:charset UTF-8; Set File:charset UTF-8

Then when I visit a UTF8 site, if found garbled, as long as the lftp command prompt below the input UTF8 can adjust the encoding normal. Similarly, if the visit GBK found garbled input GBK, immediately normal.

The following explains the use of lftp

1. Login FTP

Code:

LFTP Username: password @ftp address: Transfer port (default 21)

For example: $ lftp test:[email protected]


You can also log in without the user name, and then use the login command in the interface interface to log in with the specified account, the password is not displayed.

lftp [email protected]:p ORT

For example: $ lftp [email protected]

Password:

And then it went into the. (The password you enter here is a passcode, and the password is not displayed under Linux)

2. viewing files and changing directories

Code:

Ls
CD corresponding to FTP directory

In the Lftp terminal, the front with an L command such as LCD, refers to the local, is in the operation of the machine, and the corresponding does not have this l, is the operation of the FTP site. There is also to execute the local terminal command, you can also use the front with a! way. In this way, together, the terminal, the local operation is very much put all over.
For example, view all files on FTP that have an mp3 extension:

Code:

Find. -name "*.mp3"

Code:

lftp [Email protected]:/> LCD

LCD success, local directory =/home/cyq

lftp [Email protected]:/>

3. Download
Get can of course, can also

Code:

Mget-c *.pdf

Download all PDF files in a way that allows for the continuation of the breakpoint. M stands for Multi

Code:

Mirror aaa/

The entire AAA directory is downloaded and subdirectories are automatically copied

Code:

PGET-C-N-file.dat

Download file.dat with up to 10 threads to allow for a continuation of the breakpoint
You can use the default value by setting the value of Pget:default-n.

4. Upload
The same put,mput, is the operation of the file, and download similar.

Code:

Mirror-r Local Directory Name

The local directory is passed back to the FTP site in an iterative way, including subdirectories.

5, Mode settings.

Code:

Set Ftp:charset GBK

Remote FTP site with GBK encoding, corresponding to set to UTF8, as long as the replacement GBK for UTF8.

Code:

Set File:charset UTF8

The local charset is set to UTF8, if you are GBK, change accordingly.

Code:

Set Ftp:passive-mode 1

Using passive mode login, some site requirements must be passive mode or active mode to log in, this switch is set this. 0 represents no Passive mode.

6. Bookmarks
In fact, the command line can also have bookmarks at the Lftp terminal prompt:

Code:

Bookmark Add USTC

You can store the FTP site currently being browsed with USTC as a label. Later in the shell terminal, directly

Code:

Lftp USTC

You can automatically fill in the user name, password, into the corresponding directory.

Code:

Bookmark Edit

The editor is called to modify the bookmark manually. Of course, you can also see that this bookmark is actually a simple text file. Password, user names can be seen.

7. Configuration Files
/etc/lftp.conf
In general, I will add these lines:

Reference:

Set Ftp:charset GBK
Set File:charset UTF8
Set Pget:default-n 5

In this way, you don't have to make orders every time you enter. The other set can tab and help to see.

Here are the common commands

Ls

Displays a list of remote files (ILS displays a list of local files). # l means local ILS is special.

Cd

Switch the remote directory (LCD switch local directory).

Get

Download the remote file.

Mget

Download the remote file (you can use a wildcard character, which is *).

Pget

Use multiple threads to download remote files with a preset of five.

Mirror

Download/upload (mirror-r)/Synchronize the entire directory.

Put

Upload the file.

Mput

Upload multiple files (wildcard characters are supported).

Mv

Move the remote file (the remote file renamed).

Rm

Delete the remote file.

Parameter-r, recursive delete folder

Mrm

Delete multiple remote files (wildcard characters are supported).

Mkdir

Create a remote directory.

RmDir

Delete the remote directory.

Pwd

Displays the directory where the remote is currently located (LPWD displays the local directory).

Du

Calculate the size of the remote directory

Set Net:limit-rate 10000,10000

Limit upload to download each 10kb/s

Set Ftp:charset GBK

Setting up remote FTP site with GBK encoding

!

command to execute local shell (because Lftp does not have lls, it can be replaced by!ls)

Lcd

Switch Local Directory

Lpwd

Show Local Directory

Alias

Defining aliases

Bookmark

Set bookmarks.

Exit

Exit FTP

Linux System FTP command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.