FTP命令详解(含操作实例)

以下是微软命令行FTP客户端命令大全,如果你想使用“未加工(RAW)”FTP命令而非下面翻译过的请参考:http://www.nsftools.com/tips/RawFTP.htm

 

操作实例环境:

主机(FTP客户端):192.168.65.1  window 7  64bit

远程FTP服务器:192.168.65.131   redhat 5   vsftp

 

账号:dylan

密码:dylan

 

命令行选项

1.1 选项介绍

我们在命令行用以下选项使用FTP
ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]

· -v -  禁止显示远程服务器相应信息

· -n -  禁止自动登录

· -i -   多文件传输过程中关闭交互提示

· -d -  启用调试,显示所有客户端与服务器端传递的命令

· -g -  禁用文件名通配符,允许在本地文件和路径名中使用

· -s:filename - 指定包含 FTP 命令的文本文件;命令在FTP启动后自动运行。此参数中没有空格。可替代重定向符(>)使用。

· -a -  在绑字数据连接时使用所有本地接口

· -w:windowsize - 覆盖默认的传输缓冲区大小 65535

· computer -  指定远程电脑计算机名或IP地址。此参数必须放到最后。

1.2 操作实例

-v -  禁止显示远程服务器相应信息

使用前:

C:\Users\Administrator>ftp 192.168.65.131

连接到 192.168.65.131

220 **************Welcome to blah vsFTP service.**************

用户(192.168.65.131:(none)): dylan

331 Please specify the password.

密码:

230 Login successful.

ftp> status

连接到 192.168.65.131

类型: ascii;详细开 ;铃声关 ;提示开 ;通配

调试关 ;哈希标记打印关 。

ftp> dir

200 PORT command successful. Consider using PASV.

150 Here comes the directory listing.

drwxrwxr-x    2 502      504          4096 Dec 07 15:36 ftp

-rw-rw-r--    1 502      504             0 Dec 07 15:35 hello.txt

226 Directory send OK.

ftp: 收到 128 字节,用时 0.00秒 128.00千字节/秒。

使用后:

C:\Users\Administrator>ftp -v 192.168.65.131

用户(192.168.65.131:(none)): dylan

密码:

ftp> dir

drwxrwxr-x    2 502      504          4096 Dec 07 15:36 ftp

-rw-rw-r--    1 502      504             0 Dec 07 15:35 hello.txt

 

 

 

-n -  禁止自动登录

C:\Users\Administrator>ftp -n 192.168.65.131

连接到 192.168.65.131

220 **************Welcome to blah vsFTP service.**************

C:\Users\Administrator>ftp -nv 192.168.65.131

ftp> user dylan dylan

ftp> dir

drwxrwxr-x    2 502      504          4096 Dec 07 15:36 ftp

-rw-rw-r--    1 502      504             0 Dec 07 15:35 hello.txt

 

-i -   多文件传输过程中关闭交互提示

使用前

 

ftp> mget *.txt

mget hello.txt? n

 

使用后

ftp> mget *.txt

 

注意:单文件传输不影响

 

-d -  启用调试,显示所有客户端与服务器端传递的命令

C:\Users\Administrator>ftp -nvd 192.168.65.131

ftp> user dylan dylan

---> USER dylan

---> PASS dylan

ftp> dir

---> PORT 192,168,65,1,236,113

---> LIST

drwxrwxr-x    2 502      504          4096 Dec 07 15:36 ftp

-rw-rw-r--    1 502      504             0 Dec 07 15:35 hello.txt

 

-g -  禁用文件名通配符,允许在本地文件和路径名中使用

ftp> dir he*.txt

-rw-rw-r--    1 502      504             0 Dec 07 15:35 hello.txt

ftp> mget hell*.txt

mget hell*.txt? y

Failed to open file.

ftp> get hell*.txt

Failed to open file.

 

-s:filename - 指定包含 FTP 命令的文本文件;命令在FTP启动后自动运行。此参数中没有空格。可替代重定向符(<)使用。

编写包含FTP命令的文件:dir.ftp

open 192.168.65.131

user dylan dylan

dir

 

调用:

C:\Users\Administrator>ftp -ivns:e:\ftp\dir.ftp

ftp> open 192.168.65.131

ftp> user dylan dylan

ftp> dir

drwxrwxr-x    2 502      504          4096 Dec 07 15:36 ftp

-rw-rw-r--    1 502      504             0 Dec 07 15:35 hello.txt

 

 

 

 

 

 

 

说明:其他几个不常用的先不做介绍以后有机会再补上。

 

 

 

 

客户端命令

2.1 命令概览

· ! -    执行本地命令

· ? -    显示FTP命令的说明

· append -   向远程服务器追加本地文件

· ascii -   设置文件传输类型为ASCII,默认类型

· bell -    每一个传输命令完成触发一次响铃(默认关闭)

· binary -   设置文件传输类型为binary(二进制传输) 

· bye -     结束FTP会话并退出

· cd -   改变远程工作目录

· close -   结束FTP会话并返回命令行

· debug -   开关调试(默认关闭)

· delete -   删除远程单个文件

· dir -   显示远程目录文件盒子目录列表

· disconnect -  从远程断开,重新获得FTP提示框

· get -   复制单个远程文件到本地

· glob -      开关文件名通配符(默认ON

· hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF) 为每个缓冲区传输切换打印“#”(哈希标记打印)

· help -  显示FTP命令帮助信息(用法通”?“)

· lcd -   改变本地工作目录

· literal - Sends arguments, verbatim, to the remote FTP server 向远程FTP服务器逐字发送参数(发送任意 ftp 命令)

· ls -  显示远程目录文件和子目录的简短列表(只有文件名和目录名)

· mdelete -   删除远程一个或多个文件

· mdir -   列出多个远程目录的内容

· mget -  复制一个或多个远程文件至本地

· mkdir -  创建一个远程目录

· mls -  列出多个远程目录的内容

· mput -  复制一个或多个本地文件到远程

· open -  连接到指定的FTP服务器

· prompt -  开关交互提示(默认为ON

· put -  复制一个本地文件到远程

· pwd -   显示远程当前工作目录(字面意思:打印工作目录)

· quit -   结束FTP会话并退出FTP(功能通bye

· quote - Sends arguments, verbatim, to the remote FTP server (same as "literal") 发送任意 ftp 命令??

· recv -  复制远程文件到本地

· remotehelp - 显示远程命令帮助

· rename -   重命名远程文件

· rmdir -  删除远程目录

· send -   复制一个本地文件到远程(功能通put

· status -  显示当前FTP连接状态

· trace -  开关数据包追踪(默认为OFF

· type -  设置文件传输类型(默认为ASCII

· user -  发送新用户信息

· verbose -    开关详细模式

 

 

 

 

 

2.2 操作实例

! -    执行本地命令

ftp> !dir

 驱动器 中的卷是 文档

 卷的序列号是 0003-E430

 

 E:\ftp 的目录

 

2015/06/06  11:44    <DIR>          .

2015/06/06  11:44    <DIR>          ..

2015/06/06  09:23                42 dir.ftp

2015/06/06  11:44                10 localhello.txt

               2 个文件             52 字节

               2 个目录 51,202,547,712 可用字节

? -    显示FTP命令的说明

 

append -  向远程服务器追加本地文件

语法:Syntax: append local-file [remote-file]

注意:如果remote-file 未指定默认与local-file一致

 

[dylan@Redhat ~]$ cat hello.txt

ftp> append localhello.txt hello.txt

[dylan@Redhat ~]$ cat hello.txt

hello ftp.

ftp> append hello.txt

[dylan@Redhat ~]$ cat hello.txt

hello ftp.hello there!!!

ascii -   设置文件传输类型为ASCII,默认类型

ftp> ascii

200 Switching to ASCII mode.

 

binary -   设置文件传输类型为binary(二进制传输) 

ftp> binary

200 Switching to Binary mode.

bye -     结束FTP会话并退出

ftp> bye

 

C:\Users\Administrator>

cd -   改变远程工作目录

ftp> cd ftp

ftp> dir

-rw-rw-r--    1 502      504             0 Dec 07 15:36 ftp.txt

 

close -   结束FTP会话并返回命令行

ftp> close

ftp> dir

未连接。

ftp> open 192.168.65.131

ftp> user dylan

密码:

debug -  开关调试(默认关闭)

ftp> debug

调试 开 。

ftp> dir

---> TYPE A

---> PORT 192,168,65,1,252,103

---> LIST

-rw-rw-r--    1 502      504             0 Dec 07 15:36 ftp.txt

---> TYPE I

delete -   删除远程单个文件

ftp> del ftp.txt

---> DELE ftp.txt

dir -  显示远程目录文件盒子目录列表

ftp> dir

drwxrwxr-x    2 502      504          4096 Dec 07 19:22 ftp

-rw-rw-r--    1 502      504            24 Dec 07 19:00 hello.txt

disconnect -  从远程断开,重新获得FTP提示框

ftp> disconn

ftp> dir

未连接。

ftp> open 192.168.65.131

ftp> user dylan

密码:

get -   复制单个远程文件到本地

ftp> get hello.txt

ftp> !dir

 

2015/06/06  12:31                24 hello.txt

 

glob - 开关文件名通配符(默认ON

ftp> glob

通配 关 。

ftp> mget *.txt

Failed to open file.

help - 显示FTP命令帮助信息(用法通”?“)

ftp> help dir

dir             列出远程目录的内容

lcd -  改变本地工作目录

ftp> lcd e:\ftp

目前的本地目录 E:\ftp

ls - 显示远程目录文件和子目录的简短列表(只有文件名和目录名)

ftp> ls

ftp

hello.txt

mdelete -  删除远程一个或多个文件

ftp> ls

1.tmp

2.tmp

3.tmp

ftp

Hello.txt

ftp> mdel *.tmp

ftp> ls

ftp

hello.txt

mdir -  列出多个远程目录的内容

ftp> mdir - ftp -

drwxrwxr-x    2 502      504          4096 Dec 07 19:47 ftp

-rw-rw-r--    1 502      504            24 Dec 07 19:00 hello.txt

drwxr-xr-x    2 502      504          4096 Dec 07 19:31 tmp

-rw-rw-r--    1 502      504             0 Dec 07 19:47 1.tmp

-rw-rw-r--    1 502      504             0 Dec 07 19:47 2.tmp

-rw-rw-r--    1 502      504             0 Dec 07 19:47 3.tmp

mget -  复制一个或多个远程文件至本地

ftp> mget 1.tmp 2.tmp 3.tmp

mkdir - 创建一个远程目录

ftp> mkdir tmp

ftp> dir

drwxrwxr-x    2 502      504          4096 Dec 07 19:22 ftp

-rw-rw-r--    1 502      504            24 Dec 07 19:00 hello.txt

drwxr-xr-x    2 502      504          4096 Dec 07 19:31 tmp

· 

mls - 列出多个远程目录的内容

Syntax: mls remote-files [ ...] local-file

 

ftp> mls ftp -

ftp/1.tmp

ftp/2.tmp

ftp/3.tmp

mput -  复制一个或多个本地文件到远程

ftp> mput *.tmp

ftp> ls

1.tmp

2.tmp

3.tmp

 

open -  连接到指定的FTP服务器

ftp> open 192.168.65.131

ftp> user dylan

密码:

prompt -  开关交互提示(默认为ON

ftp> mget *.tmp

mget 1.tmp? n

mget 2.tmp? n

mget 3.tmp? n

put - 复制一个本地文件到远程

ftp> put 1.tmp

pwd - 显示远程当前工作目录(字面意思:打印工作目录)

ftp> pwd

257 "/usr/dylan"

quit -  结束FTP会话并退出FTP(功能通bye

ftp> quit

 

C:\Users\Administrator>

recv - 复制远程文件到本地

ftp> recv 1.tmp

remotehelp - 显示远程命令帮助

ftp> remotehelp CWD

214-The following commands are recognized.

 ABOR ACCT ALLO APPE CDUP CWD  DELE EPRT EPSV FEAT HELP LIST MDTM MKD

 MODE NLST NOOP OPTS PASS PASV PORT PWD  QUIT REIN REST RETR RMD  RNFR

 RNTO SITE SIZE SMNT STAT STOR STOU STRU SYST TYPE USER XCUP XCWD XMKD

 XPWD XRMD

rename -  重命名远程文件

ftp> rename 1.tmp 1.tmp.bak

ftp> ls

1.tmp.bak

rmdir - 删除远程目录

ftp> rmdir tmp

send -  复制一个本地文件到远程(功能通put

Syntax: send local-file [remote-file]

 

ftp> send 1.tmp

status - 显示当前FTP连接状态

ftp> status

连接到 192.168.65.131

类型: binary;详细关 ;铃声开 ;提示关 ;通配

调试关 ;哈希标记打印关 。

type - 设置文件传输类型(默认为ASCII

ftp> type

使用 binary 模式传送文件。

verbose -   开关详细模式

ftp> verbose

详细模式 开 。

 

补充

3.1 ASCII模式和BINARY模式的区别

ASCII模式和BINARY模式的区别是回车换行的处理,binary模式不对数据进行任何处理,asci模式将回车换行转换为本机的回车字符,比如Unix下是\n,Windows下是\r\n,Mac下是\r 

 

 

 

 

 

 

 

 

  • 25
    点赞
  • 190
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
Java可以通过FTP工具类来操作FTP,以下是一个示例: ``` import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.SocketException; import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPReply; public class FTPUtil { private static final String FTP_ADDRESS = "ftp服务器地址"; private static final int FTP_PORT = 21; private static final String FTP_USERNAME = "ftp用户名"; private static final String FTP_PASSWORD = "ftp密码"; // 连接到FTP服务器 public static FTPClient connectFTP() throws SocketException, IOException { FTPClient ftpClient = new FTPClient(); ftpClient.connect(FTP_ADDRESS, FTP_PORT); ftpClient.login(FTP_USERNAME, FTP_PASSWORD); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { ftpClient.disconnect(); throw new IOException("连接FTP服务器失败"); } return ftpClient; } // 上传文件到FTP服务器 public static void uploadFile(String remotePath, String fileName, InputStream input) throws IOException { FTPClient ftpClient = null; try { ftpClient = connectFTP(); ftpClient.changeWorkingDirectory(remotePath); // 切换到上传目录 ftpClient.storeFile(fileName, input); } finally { if (ftpClient != null) { ftpClient.logout(); ftpClient.disconnect(); } } } // 从FTP服务器下载文件 public static void downloadFile(String remotePath, String fileName, OutputStream output) throws IOException { FTPClient ftpClient = null; try { ftpClient = connectFTP(); ftpClient.changeWorkingDirectory(remotePath); // 切换到下载目录 ftpClient.retrieveFile(fileName, output); } finally { if (ftpClient != null) { ftpClient.logout(); ftpClient.disconnect(); } } } // 删除FTP服务器上的文件 public static boolean deleteFile(String remotePath, String fileName) throws IOException { FTPClient ftpClient = null; try { ftpClient = connectFTP(); ftpClient.changeWorkingDirectory(remotePath); // 切换到删除目录 return ftpClient.deleteFile(fileName); } finally { if (ftpClient != null) { ftpClient.logout(); ftpClient.disconnect(); } } } } ``` 使用方式: 上传文件: ``` File file = new File("本地文件路径"); InputStream input = new FileInputStream(file); FTPUtil.uploadFile("上传目录", "上传的文件名", input); ``` 下载文件: ``` OutputStream output = new FileOutputStream(new File("本地文件路径")); FTPUtil.downloadFile("下载目录", "下载的文件名", output); ``` 删除文件: ``` FTPUtil.deleteFile("删除目录", "删除的文件名"); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值