Home  >  Article  >  php教程  >  Linux ftp command usage

Linux ftp command usage

高洛峰
高洛峰Original
2016-12-20 09:24:431413browse

Category

There are many related FTP (client and server construction are not discussed here), which are roughly divided into command line and GUI graphical interface software.

1. The graphical interface includes

gftp

ftp client under gnome

crossftp

A stable ftp client and synchronization tool based on Java. Excellent Chinese/Unicode support.

Kftpgrabber

FTP client under KDE supports encoding selection. Good support for Chinese

filezilla

Good support for Chinese

krusader

You can also enter ftp://ip through the browser to use

If you like it, you can install it through apt-get or aptitude.

2. CLI (command line) mainly includes ftp and lftp

(1) ftp

1. Connect to ftp server

Format: ftp [hostname | ip-address]

a) Enter at the Linux command line: ftp 10.18.34.115

  b) The server asks you for your username and password, enter yint and the corresponding password respectively, and wait until the authentication is passed.

Or use the following format

ftp - -i -n IP_ADDRESS

user USERNAME PASSWORD

For example:

ftp -i -n 172.17 .17.17

user PUB 123456

is also available Write a script to log in automatically.


cyq@cyq-desktop:~/Desktop/shell$ cat ftp.sh

#!/bin/sh

ftp -i -n 172.17.17.17

<< !

user PUB 123456

!


This way you can log in automatically.

2. Download files

The two commands get and mget are usually used to download files.

 a) get

 Format: get [remote-file] [local-file]

 Transfer the file from the remote host to the local host.

 If you want to get E:/rose/1.bmp on the server ,then

 ftp> get /rose/1.bmp 1.bmp (Enter)

 b) mget   

 Format: mget [remote-files]

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

 If you want to get all the files under E:/rose/ on the server, then

 ftp> cd /rose

 ftp> mget *.* (Enter)

 Note: The files are downloaded to the current directory of the Linux host . For example, if you run the ftp command under /root/yint, the files will be downloaded to /root/yint.

 3. Upload files

 a) put

 Format: put local-file [remote-file]

 Transmit a local file to the remote host.

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

 ftp>put 1.bmp/rose/333.bmp (Enter)

 b) mput

 Format: mput local-files

 Place the local host Transfer a batch of files to the remote host.

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

ftp> cd /rose (Enter) ftp> mput *.bmp (return Car)

Note: The uploaded files come from the current directory of the host. For example, if you run the ftp command under /root/yint, only the files linux under /root/yint will be uploaded to the server E:/rose.

 4. Disconnect

 bye: Disconnect from the server.

  ftp> bye (Enter)

(2) lftp

When using lftp to access some domestic ftp servers, the Chinese that is often seen is garbled. This is caused by the inconsistency between the server and local encoding.

Solution:

Create a new file ~/.lftprc or ~/.lftp/rc in the home directory

For example, I enter in the terminal:

gedit ~/.lftprc #Create a .lftprc file in the current directory

Then enter the following content in the pop-up dialog box:

debug 3

set ftp:charset GBK

set file:charset UTF-8

#set ftp:passive-mode no

#alias utf8 " set ftp:charset UTF-8"

#alias gbk " set ftp:charset GBK"

The above lines mean

Set the encoding method of the local and ftp server

alias is to use the alias command

If you have friends who often use ftp servers with different encodings, or who often use different options, you can set some aliases, which will be much more convenient.

For example:


I often access gbk encoded ftp, and utf8 encoded ftp, then I write

code like this in ~/.lftp:

alias gbk set ftp:charset gbk; set file:charset UTF-8

alias utf8 set ftp:charset UTF-8; set file:charset UTF-8


So when I visit a utf8 site, if I find garbled characters, I just need to enter utf8 under the command prompt of lftp to adjust the encoding to normal. In the same way, if you find garbled characters when accessing gbk, just enter gbk and it will be normal immediately.

The following explains how to use lftp

1. Log in to ftp

Code:

lftp Username: Password @ftp address: Transport port (default 21)

For example: $ lftp test:123456@172.17.17.17


You can also log in without a username first, and then use the login command in the interface to log in with the specified account. The password will not be displayed.

lftp user@site:port

For example: $ lftp test@172.17.17.17

Password:

Then enter. (The password entered here is the password, and the password is not displayed under Linux)

2. View files and change directories

Code:

ls
cd corresponds to the ftp directory

In the lftp terminal, the command with an l in front For example, lcd refers to local, which is the operation on the local machine, and the corresponding one without this l is the operation on ftp site. Also, to execute local terminal commands, you can also use a ! in front of it. In this way, when combined, terminal and local operations can be easily performed.
For example, view all files with mp3 extension on ftp:

Code:

find . -name "*.mp3"

Code:

lftp test@172.17.17.17:/> lcd

lcd Successful, local directory =/home/cyq

lftp test@172.17.17.17:/>

3. Downloading
get is of course possible, but also

Code:

mget -c *.pdf

Download all pdf files in a way that allows resumed downloading. m stands for multi

Code:

mirror aaa/

Download the entire aaa directory, and the subdirectories will be automatically copied

Code:

pget -c -n 10 file.dat

Up to 10 threads can download file.dat in a way that allows resumed downloading
You can use the default value by setting the value of pget:default-n.

4. Upload
The same put and mput are operations on files, similar to downloading.

Code:

mirror -R Local directory name

Reversely upload the local directory to the ftp site in an iterative manner (including subdirectories).

5. Mode setting.

Code:

set ftp:charset gbk

The remote ftp site is encoded with gbk, and the corresponding setting is utf8, just replace gbk with utf8.

Code:

set file:charset utf8

The local charset is set to utf8. If you are gbk, change it accordingly.

Code:

set ftp:passive-mode 1

Use passive mode to log in. Some sites require passive mode or active mode to log in. This switch is used to set this. 0 means no passive mode is used.

6. Bookmarks
In fact, you can also have bookmarks on the command line. In the lftp terminal prompt:

Code:

bookmark add ustc

You can store the ftp site you are currently browsing with ustc as a tag stand up. In the future, in the shell terminal, directly

code:

lftp ustc

will automatically fill in the user name and password and enter the corresponding directory.

Code:

bookmark edit

will call the editor to manually modify the bookmark. Of course, you can also see that this bookmark is actually a simple text file. Password and username can be seen.

7. Configuration file
/etc/lftp.conf
Generally, I will add these lines:

Quote:

set ftp:charset gbk
set file:charset utf8
set pget:default-n 5

This way, you don’t have to type commands every time you enter. For other sets, you can tab and help to see them.

The following are commonly used commands

ls

Display the remote file list (ils displays the local file list). # l means that local ils is special

cd

switch the remote directory (lcd switches the local directory).

get

Download remote files.

mget

Download remote files (you can use wildcards, that is, *).

pget

Use multiple threads to download remote files, the default is five.

mirror

Download/upload (mirror -R)/synchronize the entire directory.

put

Upload files.

mput

Upload multiple files (supports wildcards).

mv

Move remote files (rename remote files).

rm

Delete remote files.

Parameter -r, recursively delete folders

mrm

Delete multiple remote files (supports wildcards).

mkdir

Create a remote directory.

rmdir

Delete the remote directory.

pwd

displays the current remote directory (lpwd displays the local directory).

du

Calculate the size of the remote directory

set net:limit-rate 10000,10000

Limit upload and download to 10KB/s each

set ftp:charset gbk

Set the remote ftp site to use gbk encoding

!

Execute local shell commands (since lftp does not have lls, you can use !ls instead)

lcd

Switch local directory

lpwd

Display local directory

alias

Define alias

bookmark

set Bookmark.

exit

Exit ftp



For more articles related to the use of Linux ftp commands, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn