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.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章