Ftp笔记

来源:互联网 发布:模拟电话号码软件 编辑:程序博客网 时间:2024/04/26 01:58

启动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.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原创粉丝点击