FTP命令详解

来源:互联网 发布:常州瑞声科技 知乎 编辑:程序博客网 时间:2024/04/24 19:02

FTP 命令是 Internet 用户使用最频繁的命令之一,不论是在 DOS 还是 UNIX 操作系统下使用 FTP ,都会遇到大量的 FTP 内部命令。 熟悉并灵活应用 FTP 的内部命令,可以大大方便使用者,并收到事半功倍之效。

&  FTP 的命令行格式为: ftp -v -d -i -n -g [ 主机名 ] ,其中

-v 显示远程服务器的所有响应信息;
-n 限制 ftp 的自动登录,即不使用 .netrc 文件;
-d 使用调试方式;
-g 取消全局文件名。

&  FTP 使用的内部命令如下 ( 中括号表示可选项 ) :

1.![cmd[args] :在本地机中执行交互 sh*ll , exit 回到 ftp 环境,如: !ls*.zip

2.$ macro-ame[args] : 执行宏定义 macro-name 。

3.account[password] : 提供登录远程系统成功后访问系统资源所需的补充口令。

4.append local-file[remote-file] :将本地文件追加到远程系统主机,若未指定远程系统文件名,则使用本地文件名。

5.ascii :使用 ascii 类型传输方式。

6.bell :每个命令执行完毕后计算机响铃一次。

7.bin :使用二进制文件传输方式。

8.bye :退出 ftp 会话过程。

9.case :在使用 mget 时,将远程主机文件名中的大写转为小写字母。

10.cd remote-dir :进入远程主机目录。

11.cdup :进入远程主机目录的父目录。

12.chmod mode file-name :将远程主机文件 file-name 的存取方式设置为 mode ,如: chmod 777 a.out 。

13.close :中断与远程服务器的 ftp 会话 ( 与 open 对应 ) 。

14.cr :使用 asscii 方式传输文件时,将回车换行转换为回行。

15.delete remote-file :删除远程主机文件。

16.debug[debug-value] :设置调试方式, 显示发送至远程主机的每条命令,如: deb up 3 ,若设为 0 ,表示取消 debug 。

17.dir[remote-dir][local-file] :显示远程主机目录,并将结果存入本地文件

18.disconnection :同 close 。

19.form format :将文件传输方式设置为 format ,缺省为 file 方式。

20.get remote-file[local-file] : 将远程主机的文件 remote-file 传至本地硬盘的 local-file 。

21.glob :设置 mdelete , mget , mput 的文件名扩展,缺省时不扩展文件名,同命令行的 -g 参数。

22.hash :每传输 1024 字节,显示一个 hash 符号 (#) 。

23.help[cmd] :显示 ftp 内部命令 cmd 的帮助信息,如: help get 。 与?作用相同。

24.idle[seconds] :将远程服务器的休眠计时器设为 [seconds] 秒。

25.image :设置二进制传输方式 ( 同 binary) 。

26.lcd[dir] :将本地工作目录切换至 dir 。

27.ls[remote-dir][local-file] :显示远程目录 remote-dir , 并存入本地文件 local-file 。

28.macdef macro-name :定义一个宏,遇到 macdef 下的空行时,宏定义结束。

29.mdelete[remote-file] :删除远程主机文件。

30.mdir remote-files local-file :与 dir 类似,但可指定多个远程文件,如 : mdir *.o.*.zipoutfile 。

31.mget remote-files :传输多个远程文件。

32.mkdir dir-name :在远程主机中建一目录。

33.mls remote-file local-file :同 nlist ,但可指定多个文件名。

34.mode[modename] :将文件传输方式设置为 modename , 缺省为 stream 方式。

35.modtime file-name :显示远程主机文件的最后修改时间。

36.mput local-file :将多个文件传输至远程主机。

37.newer file-name : 如果远程机中 file-name 的修改时间比本地硬盘同名文件的时间更近,则重传该文件。

38.nlist[remote-dir][local-file] :显示远程主机目录的文件清单,并存入本地硬盘的 local-file 。

39.nmap[inpattern outpattern] :设置文件名映射机制, 使得文件传输时,文件中的某些字符相互转换, 如: nmap $1.$2.$3[$1 , $2].[$2 , $3] ,则传输文件 a1.a2.a3 时,文件名变为 a1 , a2 。 该命令特别适用于远程主机为非 UNIX 机的情况。

40.ntrans[inchars[outchars] :设置文件名字符的翻译机制,如 ntrans1R ,则文件名 LLL 将变为 RRR 。

41.open host[port] :建立指定 ftp 服务器连接,可指定连接端口。

42.passive :进入被动传输方式。

43.prompt :设置多个文件传输时的交互提示。

44.proxy ftp-cmd :在次要控制连接中,执行一条 ftp 命令,该命令允许连接两个 ftp 服务器,以在两个服务器间传输文件。第一条 ftp 命令必须为 open ,以首先建立两个服务器间的连接。

45.put local-file[remote-file] :将本地文件 local-file 传送至远程主机。

46.pwd :显示远程主机的当前工作目录。

47.quit :同 bye ,退出 ftp 会话。

48.quote arg1 , arg2... :将参数逐字发至远程 ftp 服务器,如: quote syst.

49.recv remote-file[local-file] :同 get 。

50.reget remote-file[local-file] :类似于 get , 但若 local-file 存在,则从上次传输中断处续传。

51.rhelp[cmd-name] :请求获得远程主机的帮助。

52.rstatus[file-name] :若未指定文件名,则显示远程主机的状态, 否则显示文件状态。

53.rename[from][to] :更改远程主机文件名。

54.reset :清除回答队列。

55.restart marker :从指定的标志 marker 处,重新开始 get 或 put ,如: restart 130 。

56.rmdir dir-name :删除远程主机目录。

57.runique :设置文件名只一性存储,若文件存在,则在原文件后加后缀 .1 , .2 等。

58.send local-file[remote-file] :同 put 。

59.sendport :设置 PORT 命令的使用。

60.site arg1 , arg2... :将参数作为 SITE 命令逐字发送至远程 ftp 主机。

61.size file-name :显示远程主机文件大小,如: site idle 7200 。

62.status :显示当前 ftp 状态。

63.struct[struct-name] :将文件传输结构设置为 struct-name , 缺省时使用 stream 结构。

64.sunique :将远程主机文件名存储设置为只一 ( 与 runique 对应 ) 。

65.system :显示远程主机的操作系统类型。

66.tenex :将文件传输类型设置为 TENEX 机的所需的类型。

67.tick :设置传输时的字节计数器。

68.trace :设置包跟踪。

69.type[type-name] :设置文件传输类型为 type-name ,缺省为 ascii ,如 :type binary ,设置二进制传输方式。

70.umask[newmask] :将远程服务器的缺省 umask 设置为 newmask ,如: umask 3

71.user user-name[password][account] :向远程主机表明自己的身份,需要口令时,必须输入口令,如: user anonymousmy@email 。 SDDSA

72.verbose :同命令行的 -v 参数,即设置详尽报告方式, ftp 服务器的所有响 应都将显示给用户,缺省为 on.

&  FTP 外部命令:

&  第一组:

bye Terminate ftp session and exit

quit Terminate ftp session and exit

&  第二组:

open Connect to remote tftp ,例如 ftp> open 192.168.1.6

user Send new user information 再输入一次用户名和口令 ( 有点像 UNIX 下的 SU) 。

close Terminate ftp session

disconnect Terminate ftp session

&  第三组:

? Print local help information

help Print local help information

remotehelp Get help from remote server = rhelp

&  第四组:

ascii Set ascii transfer type 切换传输模式为文字模式 ( 只能用来传送 DOC 文件,因为是 7-BIT)

binary Set binary transfer type 切换传输模式为二进制模式 ( 除文字文件外皆用此模式 ) = image

type Set file transfer type 让你更改或显示目前传输模式

&  第五组:

cd Change remote working directory ---cd.. = cdup cd \

lcd Change local working directory

pwd Print working directory on remote machine

! Escape to the shell , 例如: !dir 直接用它相当 bye

&  第六组:

delete Delete remote file

mdelete Delete multiple files

rename Rename file

&  第七组:

dir List contents of remote directory 相当于 LS-L(LIST-LONG)

rmdir Remove directory on the remote machine 象 DOS 下的 RD( 删除子目录 ) 一样

mkdir Make directory on the remote machine

ls List contents of remote directory 有点象 UNIX 下的 LS(LIST) 命令

mls List contents of multiple remote directori

mdir List contents of multiple remote directori

&  第八组:

get Receive file

mget Get multiple files

put Send one file

mput Send multiple files

recv Receive file 相当于 GET(RECV 为 RECEWE 的简写 )

send Send one file 相当于 PUT

&  第九组:

status Show current status

bell Beep when command completed

hash Toggle printing `#' for each buffe 切换 # 字号的出现,每一个 # 字号表示传送了 1024 / 8192BYTES

prompt Force interactive prompting on multiple commands

verbose Toggle verbose mode 切换所有文件传输过程的显示

&  第十组:

quote Send arbitrary ftp command

literal Send arbitrary ftp command

glob Toggle metacharacter expansion of

trace Toggle packet tracing

debug Toggle debugging mode

append Append to a file

&  FTP 常用命令操作实例:

 

ftp出错代码对照


110 Restart marker reply. In this case, the text is exact and not left to the particular implementation; it must read: MARK yyyy = mmmm where yyyy is User-process data stream marker, and mmmm server's equivalent marker (note the spaces between markers and "=").
重新启动标志回应。这种情况下,信息是精确的并且不用特别的处理;可以这样看:标记 yyyy = mmm 中 yyyy 是用户进程数据流标记, mmmm 是服务器端相应的标记(注意在标记和等号间的空格)
-----------------------------------

120 Service ready in nnn minutes.
服务在 NNN 时间内可用
-----------------------------------

125 Data connection already open; transfer starting.
数据连接已经打开,开始传送数据 .
-----------------------------------

150 File status okay; about to open data connection.
文件状态正确,正在打开数据连接 .
-----------------------------------

200 Command okay.
命令执行正常结束 .
-----------------------------------

202 Command not implemented, superfluous at this site.
命令未被执行,此站点不支持此命令 .
-----------------------------------

211 System status, or system help reply.
系统状态或系统帮助信息回应 .
-----------------------------------

212 Directory status.
目录状态信息 .
-----------------------------------

213 File status.
文件状态信息 .
-----------------------------------

214 Help message.On how to use the server or the meaning of a particular non-standard command. This reply is useful only to the human user. 帮助信息。关于如何使用本服务器或特殊的非标准命令。此回复只对人有用。
-----------------------------------

215 NAME system type. Where NAME is an official system name from the list in the Assigned Numbers document.
NAME 系统类型。
-----------------------------------

220 Service ready for new user.
新连接的用户的服务已就绪
-----------------------------------

221 Service closing control connection.
控制连接关闭
-----------------------------------

225 Data connection open; no transfer in progress.
数据连接已打开,没有进行中的数据传送
-----------------------------------

226 Closing data connection. Requested file action successful (for example, file transfer or file abort).
正在关闭数据连接。请求文件动作成功结束(例如,文件传送或终止)
-----------------------------------

227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
进入被动模式
-----------------------------------

230 User logged in, proceed. Logged out if appropriate.
用户已登入。 如果不需要可以登出。
-----------------------------------

250 Requested file action okay, completed.
被请求文件操作成功完成
-----------------------------------

257 "PATHNAME" created.
路径已建立
-----------------------------------

331 User name okay, need password.
用户名存在,需要输入密码
-----------------------------------

332 Need account for login.
需要登陆的账户
-----------------------------------

350 Requested file action pending further information
对被请求文件的操作需要进一步更多的信息
-----------------------------------

421 Service not available, closing control connection.This may be a reply to any command if the service knows it must shut down.
服务不可用,控制连接关闭。这可能是对任何命令的回应,如果服务认为它必须关闭
-----------------------------------

425 Can't open data connection.
打开数据连接失败
-----------------------------------

426 Connection closed; transfer aborted.
连接关闭,传送中止。
-----------------------------------

450 Requested file action not taken.
对被请求文件的操作未被执行
-----------------------------------

451 Requested action aborted. Local error in processing.
请求的操作中止。处理中发生本地错误。
-----------------------------------

452 Requested action not taken. Insufficient storage space in system.File unavailable (e.g., file busy).
请求的操作没有被执行。 系统存储空间不足。 文件不可用
-----------------------------------

500 Syntax error, command unrecognized. This may include errors such as command line too long.
语法错误,不可识别的命令。 这可能是命令行过长。
-----------------------------------

501 Syntax error in parameters or arguments.
参数错误导致的语法错误
-----------------------------------

502 Command not implemented.
命令未被执行
-----------------------------------

503 Bad sequence of commands.
命令的次序错误。
-----------------------------------

504 Command not implemented for that parameter.
由于参数错误,命令未被执行
-----------------------------------

530 Not logged in.
没有登录
-----------------------------------

532 Need account for storing files.
存储文件需要账户信息
-----------------------------------

550 Requested action not taken. File unavailable (e.g., file not found, no access).
请求操作未被执行,文件不可用。
-----------------------------------

551 Requested action aborted. Page type unknown.
请求操作中止,页面类型未知
-----------------------------------

552 Requested file action aborted. Exceeded storage allocation (for current directory or dataset).
对请求文件的操作中止。 超出存储分配
-----------------------------------

553 Requested action not taken. File name not allowed
请求操作未被执行。 文件名不允许
-----------------------------------
-----------------------------------

&  这种错误跟 http 协议类似,大致是:
2 开头--成功
3 开头--权限问题
4 开头--文件问题
5 开头--服务器问题

&  对我们最有用的:
421 :一般出现在连接数多,需稍后在接;
530 :密码错误;
550 :目录或文件已经被删除。  


本文出自:http://cs.ecust.edu.cn/snwei/studypc/oftencommand/ftp.htm

0 0
原创粉丝点击