天天看點

Ftp筆記

啟動apache ftp server

> ftpd.bat  res/conf/ftpd-typical.xml(記得指定配置檔案,否則任何使用者名、密碼都無法登入!)

ftp指令解析

! : 直接退出。

delete : 删除檔案

eg: 

delete Test.java

literal : 向伺服器發送指令(server command)

eg: 

literal

[command line to send]

prompt : 關閉/開啟使用者互動模式(使用者提示)

eg:

prompt

[Interactive mode off .]

prompt

[Interactive mode on .]

send : 向伺服器發送檔案

eg:

send

[Local file] f:/test.java

[Remote file] test1.java

? : 顯示幫助資訊

eg:

ftp> ?

Commands may be abbreviated.  Commands are:

!               delete          literal         prompt          send

?               debug           ls              put             status

append          dir             mdelete         pwd             trace

ascii           disconnect      mdir            quit            type

bell            get             mget            quote           user

binary          glob            mkdir           recv            verbose

bye             hash            mls             remotehelp

cd              help            mput            rename

close           lcd             open            rmdir

debug : 打開/關閉Debug模式

eg:

debug

[Debugging on .]

debug

[Debugging off .]

ls : 列出Ftp伺服器目前目錄下的所有檔案及目錄

eg:

ls

[help

README.txt

Test.class

Test.java]

補充:ls -l : 列出Ftp伺服器目前目錄下的所有檔案及目錄的詳細資訊

put : 向Ftp伺服器發送檔案

eg:

put

[Local file] f:/permutation.java

[Remote file] permutation.java

status : 顯示目前Ftp伺服器的連接配接狀态

eg:

ftp> status

Connected to wlf.

Type: ascii; Verbose: On ; Bell: Off ; Prompting: On ; Globbing: On

Debugging: Off ; Hash mark printing: Off .

append : 将用戶端某個檔案的内容追加到Ftp伺服器某個檔案的末尾

eg:

append

[Local file] f:/test.java

[Remote file] readme.txt

(最終将兩個檔案的内容合并)

dir : 列出目前目錄下的所有檔案和目錄,與“ ls -l ”的效果相同

eg:

ftp> dir

200 Command PORT okay.

150 File status okay; about to open data connection.

drwx------   3 user group            0 Oct 29 10:41 help

drwx------   3 user group            0 Oct 29 10:49 testp

-rw-------   1 user group         1337 Oct 29 10:55 README.txt

-rw-------   1 user group         1275 Oct 18 18:08 Test.class

-rw-------   1 user group         1178 Oct 29 10:49 permutation.java

-rw-------   1 user group         1309 Oct 29 10:29 test1.java

226 Closing data connection.

ftp: 收到 379 位元組,用時 0.01Seconds 25.27Kbytes/sec.

mdelete : 一次删除Ftp伺服器上的多個檔案

eg:

ftp> mdelete

[Remote files] test1.java permutation.java

200 Command TYPE okay.

[mdelete test1.java?]

250 Requested file action okay, deleted /test1.java.

[mdelete permutation.java?]

250 Requested file action okay, deleted /permutation.java.

補充:在預設Status情況下,prompt是on的,此時執行該指令,每次删除一個檔案都會

要求确認(按回車确認);因而,如果不希望确認,可先執行prompt指令将prompt狀态

設定為off。

pwd : 顯示會話使用的遠端Ftp伺服器的目前目錄

eg:

ftp> pwd

[257 "/help" is current directory.]

trace : 打開/關閉trace模式

eg:

trace

[Packet tracing On .]

trace

[Packet tracing Off .]

ascii : 切換傳輸模式為文本

eg:

ftp> ascii

200 Command TYPE okay.

disconect : 斷開與Ftp伺服器的連接配接,但是不退出ftp指令模式

eg:

ftp> disconnect

221 Goodbye.

mdir : 列出多個遠端目錄下的檔案及子目錄

【Ftp:mdir

顯示遠端目錄中的檔案和子目錄清單。

文法

mdir RemoteFiles [ ...] LocalFile

參數

RemoteFiles

指定要檢視其清單的目錄。

LocalFile

指定要存儲清單的本地檔案。

? mdir

顯示 mdir 指令的幫助。 

注釋

可以使用 mdir 指定多個檔案。 

指定 RemoteFiles

輸入連字元 (-) 來使用遠端計算機上的目前工作目錄。

指定 LocalFile

輸入連字元 (-) 在螢幕上顯示清單。】

eg:

mdir help testp f:/list.txt (輸出到檔案)

mdir help testp - (輸出到螢幕)

mdir - help testp - (列出目前目錄、help、testp的内容到螢幕)

quit : 退出ftp指令模式

eg:

ftp> quit

221 Goodbye.

type : 顯示目前使用的檔案傳輸模式(ascii/binary)

eg:

type

[Using ascii mode to transfer files.]

binary

[200 Command TYPE okay.]

type

[Using binary mode to transfer files.]

bell : 打開/關閉Bell模式

eg:

bell

[Bell mode On .]

bell

[Bell mode off .]

get : 從遠端Ftp伺服器擷取檔案

eg:

get

[Remote file] readme.txt

[Local file] f:/readme.txt

mget : 從遠端Ftp伺服器擷取多個檔案到本機

eg:

mget

[Remote files] test.java test.class

補充:該指令不提供到本機存儲目錄指定的功能,下載下傳的檔案将預設存放

在“C:/Documents and Settings/本機目前使用者名”目錄中;擷取檔案時

可以使用通配符,如mget *.*,但是不要這樣寫mget help/*.*,要擷取

子目錄下的所有檔案,請先進入到該子目錄再擷取,如cd help再mget *.*。

quote : 與literal功能完全相同

user :  指定遠端計算機的使用者

【Ftp:user

指定遠端計算機的使用者。

文法

userUserName [Password] [Account]

參數

UserName

指定登入到遠端計算機所使用的使用者名。

Password

指定 UserName 的密碼。如果未指定密碼,但需要指定,則 ftp 會提示您輸入密碼。

Account

指定登入到遠端計算機所使用的帳戶。如果需要指定 Account,但沒有指定,則 ftp 會提示您輸入帳戶。

? user

顯示 user 指令的幫助。 】

binary : 切換到binary檔案傳輸模式

eg:

binary

[200 Command TYPE Okay.]

glob : 打開/關閉glob模式

eg:

glob

[Globbing Off .]

glob

[Globbing On .]

mkdir : 在遠端Ftp伺服器上建立一個目錄

eg:

mkdir

[Director name] mydir

[275 "/mydir" created]

recv : 使用目前檔案傳輸類型将遠端檔案複制到本地計算機。

eg:

recv

[Remote file] eee.mp3

[Local file] f:/eee.mp3

verbose : 打開/關閉verbose模式

eg:

verbose

[Verbose mode Off .]

verbose

[Verbose mode On .]

bye : 結束與遠端計算機的 FTP 會話并退出 ftp。

hash : 打開/關閉hash模式

eg:

ftp> hash

[Hash mark printing On  ftp: (2048 bytes/hash mark) .]

ftp> hash

[Hash mark printing Off  .]

mls : 允許顯示多個遠端目錄上的檔案和子目錄的簡表。

eg:

mls help testp -

mls help testp f:/list.txt

【文法

mlsRemoteFiles [ ...]LocalFile

參數

RemoteFiles

指定要檢視清單的檔案。

LocalFile

指定要存儲清單的本地檔案。

? mls

顯示 mls 指令的幫助。 

注釋

指定 RemoteFiles

輸入連字号 (-) 來使用遠端計算機上的目前工作目錄。

指定 LocalFile

輸入連字号 (-) 在螢幕上顯示清單。】

補充:dir = ls -l , 但mdir != mls(mls不支援接-l參數的寫法)

remotehelp : 顯示遠端指令的幫助。(用于literal、quote輸入的指令)

eg:

ftp> remotehelp

214-The following commands are implemented.

ABOR  APPE  CDUP  CWD   DELE  HELP  LIST  MDTM

MKD   MODE  NLST  NOOP  PASS  PASV  PORT  PWD

QUIT  REST  RETR  RMD   RNFR  RNTO  SITE  SIZE

STAT  STOR  STOU  STRU  SYST  TYPE  USER

214 End of help.

cd : 更改遠端計算機上的工作目錄。

help : 顯示ftp子指令的說明。(和?功能相同)

mput : 使用目前檔案傳輸類型将本地檔案複制到遠端計算機上。

eg:

mput test.java test.class

該指令不能指定拷貝到的遠端計算機目錄,預設使用遠端計算機上的目前工作目錄。

rename : 重命名遠端檔案。

eg:

rename fff.mp3 ilu.mp3

close : 結束與遠端伺服器的 FTP 會話,并停留在 ftp> 提示符下。

lcd : 更改本地計算機上的工作目錄。預設情況下,工作目錄是啟動 ftp 的目錄。

eg:

lcd

[Local directory now C:/Documents and Settings/dell.]

lcd f:/

[Local directory now F:/.]

open : 與指定的 FTP 伺服器連接配接。

文法:open Computer [Port]

eg:

ftp> open localhost 2121

Connected to wlf.

220 Service ready for new user.

User (wlf:(none)): admin

331 User name okay, need password for admin.

Password:

230 User logged in, proceed.

rmdir : 删除遠端目錄

eg:

rmdir help

補充:待删除的目錄下不能包含有檔案和子目錄,否則無法删除。

(完)

---------------------------------------------------------

關于status的預設狀态:

ftp> status

Connected to wlf.

Type: ascii; Verbose: On ; Bell: Off ; Prompting: On ; Globbing: On

Debugging: Off ; Hash mark printing: Off .

a.  type : 指定檔案傳輸使用ascii/binary類型。

在 ASCII 模式中,将執行網絡标準字元集間的字元轉換。例如,行尾字元在必要時根據目标作業系統進行轉換。

在傳輸可執行檔案時應該使用二進制。在二進制模式下,檔案以一位元組為機關進行傳輸。

(建議文本檔案使用ascii模式,其餘使用binary模式)

注意:在使用ascii模式傳送二進制檔案時,可能會改變檔案的大小。 

b.  verbose : 預設情況下,verbose 處于打開狀态。

verbose 處于打開狀态時,将顯示所有 ftp 響應。

檔案傳輸完成後,還會顯示與傳輸效率有關的統計資訊。

c.  bell : 預設情況下,“bell”是關閉的。 

執行完每個檔案傳輸指令後,将會切換到一個可聽見的聲音。

d.  prompt : 預設情況下,prompt 是打開的。 

在傳輸多個檔案期間,Ftp 的提示将允許您選擇性地檢索或存儲檔案。

如果 prompt 是關閉的,則 mget 和 mput 将傳輸所有檔案。  

e.  glob : 預設情況下,glob 是打開的。 

Glob 允許使用星号 (*) 和問号 (?) 作為本地檔案或路徑名的通配符。

如果關閉glob,在處理星号 (*) 和問号 (?)時将不作為通配符處理,而是當做普通字元。

f.  debug : 預設情況下,調試是關閉的。 

當打開調試時,将顯示發送到遠端計算機的每個指令,前面是大于号字元 (>)。 

ftp> debug

Debugging On .

ftp> dir

---> TYPE A

---> PORT 127,0,0,1,5,40 【本機位址:127.0.0.1,本機目前ftp會話端口5*256+40=1320】

---> LIST

drwx------   3 user group            0 Oct 29 10:41 help

drwx------   3 user group            0 Oct 29 14:49 test

-rw-------   1 user group         1337 Oct 29 10:55 README.txt

-rw-------   1 user group         1275 Oct 29 14:14 Test.class

-rw-------   1 user group         1258 Oct 29 14:14 Test.java

-rw-------   1 user group      2912148 Oct 29 11:34 ascii.mp3

-rw-------   1 user group      2912148 Oct 29 14:35 eee.mp3

-rw-------   1 user group      2891776 Oct 29 11:22 iloveu.mp3

---> TYPE I

g.  hash : 切換已傳輸的每個資料塊的數字簽名 (#) 列印。

資料塊的大小是 2048 位元組。 預設情況下,hash 是關閉的。

-----------------------------------------------------------------------

其它注意:

1、ftp:user 指令用于指定登入的使用者名,在已登入的ftp狀态下不能使用該指令。

該命名隻有在open 後輸入的使用者名或密碼錯誤時,再使用該指令再次使用其它的

使用者名和密碼。

eg:

ftp> open localhost 2121

Connected to wlf.

220 Service ready for new user.

User (wlf:(none)): admin

331 User name okay, need password for admin.

Password:

530 Authentication failed.

Login failed.

ftp> user admin

331 User name okay, need password for admin.

Password:

230 User logged in, proceed.

ftp> open localhost 2121

Connected to wlf.

220 Service ready for new user.

User (wlf:(none)): admin

331 User name okay, need password for admin.

Password:

530 Authentication failed.

Login failed.

ftp> user anonymous

331 Guest login okay, send your complete e-mail address as password.

Password:

230 User logged in, proceed.

ftp> dir

200 Command PORT okay.

150 File status okay; about to open data connection.

dr-x------   3 user group            0 Oct 29 10:41 help

dr-x------   3 user group            0 Oct 29 14:49 test

-r--------   1 user group         1337 Oct 29 10:55 README.txt

-r--------   1 user group         1275 Oct 29 14:14 Test.class

-r--------   1 user group         1258 Oct 29 14:14 Test.java

-r--------   1 user group      2912148 Oct 29 11:34 ascii.mp3

-r--------   1 user group      2912148 Oct 29 14:35 eee.mp3

-r--------   1 user group      2891776 Oct 29 11:22 iloveu.mp3

226 Closing data connection.

ftp: 收到 495 位元組,用時 0.02Seconds 30.94Kbytes/sec.

2、在使用send或put指令傳輸檔案時,遠端檔案名不要包含中文字元(ApacheFtpServer)

3、常用發送接收指令。

put、send、mput

get、recv、mget

其中mput、mget無法指定目标目錄,将使用預設的pwd及lcd列印的目錄。

4、發送或接受多個檔案時,可先關閉prompt狀态模式,避免不需要的詢問。

5、删除某個目錄下的所有檔案時,使用指令mdelete * , 然後使用rmdir删除該目錄。

不推薦使用mdelete *.*的方式,這種方法對于不含擴充名的檔案無法删除。

ftp> pwd

257 "/" is current directory.

ftp> mdelete *

200 Command TYPE okay.

550 Not a valid file "/help".

550 Not a valid file "/test".

250 Requested file action okay, deleted /Permutation.java.

250 Requested file action okay, deleted /eee.mp3.

250 Requested file action okay, deleted /list.txt.

250 Requested file action okay, deleted /lkjj.

250 Requested file action okay, deleted /readme.txt.

250 Requested file action okay, deleted /鏋夊嚌鐪塤閮戠華宀?mp3.

繼續閱讀