Linux命令完全指南

Linux ftp命令使用详解

ftp命令是最常见的FTP协议的客户端, 它是FTP协议的用户接口,使用ftp命令可以方便的同远程主机传送文件。

用法

1
ftp [-pinegvd] [host]

选项

选项说明
-AUse active mode for data transfers.
-pUse passive mode for data transfers.
-i关闭互动模式,不询问任何问题
-n不使用自动登录
-e关闭历史命令和命令编辑功能
-g关闭本地主机文件名称支持特殊字符的扩充特性;
-v显示指令执行过程
-d详细显示指令执行过程,便于排错或分析程序执行的情况;

参数

host:指定要连接的FTP服务器的主机名或ip地址。如果没有指定参数ftp则进入解释器交互模式。

ftp命令

  • ! [command [args]] : 执行本机命令
  • $ macro-name [args] : 执行由macdef命令定义的marco-name宏
  • account [passwd] : 账户登录
  • append local_file [remote-file] : 文件内容追加
  • ascii : 设定以ASCII方式传送文件
  • bell : 每完成一次文件传送,报警提示.
  • binary : 设定以二进制方式传送文件
  • bye : 终止主机FTP进程,并退出FTP管理方式.
  • case : 当为ON时,用MGET命令拷贝的文件名到本地机器中,全部转换为小写字母.
  • cd [dir] : 切换远程主机的目录
  • cdup : 返回上一级目录
  • chmod mode file-name : 改变远端主机的文件权限.
  • close : 终止远端的FTP进程,返回到FTP命令状态,所有的宏定义都被删除
  • cr: Toggle carriage return stripping during ascii type file retrieval.
  • delete remote-file :删除远端主机中的文件
  • debug [debug-value] : Toggle debugging mode.
  • dir [remote-dir] [local-dir]: 列出当前远端主机目录中的文件.如果有本地文件,就将结果写至本地文件.
  • form format : Set the file transfer form to format. The default format is “file”
  • get remote-file [local-file] : 下载文件
  • glob :Toggle filename expansion for mdelete, mget and mput.
  • hash : Toggle hash-sign (#) printing for each data block trans‐ ferred. The size of a data block is 1024 bytes.
  • help [command]: 显示命令帮助信息
  • idle [seconds]: 设置远程主机的不活动的定时器
  • lcd [dir] : 改变当前本地主机的工作目录,如果缺省,就转到当前用户的HOME目录
  • ls [remote-directory] [local-file] : 同DIR
  • macdef : 定义宏命令
  • mdelete [remote-files] : 删除多个文件
  • mdir remote-files local-file : 同 DIR
  • mget remote-files : 从远端主机接收一批文件至本地主机.
  • mkdir dir : 在远端主机中建立目录.
  • mls remote-files local-file: 同 nlist
  • mode [mode-name]: Set the file transfer mode to mode-name. The default mode is “stream” mode.
  • modtime file-name : 显示远程主机文件的最后修改时间
  • mput local-file: 批量上传文件
  • newer file-name [local-file]: 仅在远程文件更新的情况下下载文件
  • nlist [remote-file] [local-file]: 列出文件
  • nmap [impattern outpattern]: Set or unset the filename mapping mechanism
  • ntrans [inchars [outchars]]
  • open host [port]: 打开远程主机
  • prompt : Toggle interactive prompting.
  • proxy ftp-command: Execute an ftp command on a secondary control connection.
  • put local-file [remot-file]: 上传文件
  • pwd : 显示远程主机的工作目录
  • quit : 同bye
  • quote arg1 arg2 … : The arguments specified are sent, verbatim, to the remote FTP server
  • recv remote-file [local-file] # 同GET

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
ftp> ascii  # 设定以ASCII方式传送文件(缺省值)
ftp> bell # 每完成一次文件传送,报警提示.
ftp> binary # 设定以二进制方式传送文件.
ftp> bye # 终止主机FTP进程,并退出FTP管理方式.
ftp> case # 当为ON时,用MGET命令拷贝的文件名到本地机器中,全部转换为小写字母.
ftp> cd # 同UNIX的CD命令.
ftp> cdup # 返回上一级目录.
ftp> chmod # 改变远端主机的文件权限.
ftp> close # 终止远端的FTP进程,返回到FTP命令状态, 所有的宏定义都被删除.
ftp> delete # 删除远端主机中的文件.
ftp> dir [remote-directory] [local-file] # 列出当前远端主机目录中的文件.如果有本地文件,就将结果写至本地文件.
ftp> get [remote-file] [local-file] # 从远端主机中传送至本地主机中.
ftp> help [command] # 输出命令的解释.
ftp> lcd # 改变当前本地主机的工作目录,如果缺省,就转到当前用户的HOME目录.
ftp> ls [remote-directory] [local-file] # 同DIR.
ftp> macdef # 定义宏命令.
ftp> mdelete [remote-files] # 删除一批文件.
ftp> mget [remote-files] # 从远端主机接收一批文件至本地主机.
ftp> mkdir directory-name # 在远端主机中建立目录.
ftp> mput local-files # 将本地主机中一批文件传送至远端主机.
ftp> open host [port] # 重新建立一个新的连接.
ftp> prompt # 交互提示模式.
ftp> put local-file [remote-file] # 将本地一个文件传送至远端主机中.
ftp> pwd # 列出当前远端主机目录.
ftp> quit # 同BYE.
ftp> recv remote-file [local-file] # 同GET.
ftp> rename [from] [to] # 改变远端主机中的文件名.
ftp> rmdir directory-name # 删除远端主机中的目录.
ftp> send local-file [remote-file] # 同PUT.
ftp> status # 显示当前FTP的状态.
ftp> system # 显示远端主机系统类型.
ftp> user user-name [password] [account] # 重新以别的用户名登录远端主机.
ftp> ? [command] # 同HELP. [command]指定需要帮助的命令名称。如果没有指定 command,ftp 将显示全部命令的列表。
ftp> ! # 从 ftp 子系统退出到外壳。

关闭FTP连接

1
2
3
bye
exit
quit

下载文件

1
2
ftp> get readme.txt # 下载 readme.txt 文件
ftp> mget *.txt # 下载

上传文件

1
2
ftp> put /path/to/readme.txt # 上传 readme.txt 文件
ftp> mput *.txt # 可以上传多个文件