Linux ftp 不断重连代码,Linux下常用的ftp操作命令

Linux下常用的ftp操作命令

=========== 完美的分割线 =============

1.登陆ftp服务器

ftp [IP] [PORT] #登陆ftp服务器,本机登陆可以不写IP

实例演示:

[root@ftpsrv vsftpd]#ftp 127.0.0.1 21

Connected to 127.0.0.1 (127.0.0.1).220 (vsFTPd 2.2.2)

Name (127.0.0.1:root): nice331Please specify the password.

Password:230Login successful.

Remote system typeisUNIX.

Using binary mode to transfer files.

ftp>

可以看出登陆后默认为二进制传输模式

2.ftp子命令

2.1.帮助命令

ftp> ?|help #显示ftp内部命令的帮助信息

2.2.查看ftp中的文件列表(ls和dir都可以查看)

ftp>dir227 Entering Passive Mode (127,0,0,1,44,241).150Here comes the directory listing.

drwxr-xr-x 2 501 501 4096 Sep 04 07:18aaa

drwxr-xr-x 2 501 501 4096 Sep 05 08:59bbb226Directory send OK.

ftp>ls227 Entering Passive Mode (127,0,0,1,71,215).150Here comes the directory listing.

drwxr-xr-x 2 501 501 4096 Sep 04 07:18aaa

drwxr-xr-x 2 501 501 4096 Sep 05 08:59bbb226Directory send OK.

ftp>

2.3.切换ftp的目录

ftp>cd aaa      # 切换到ftp的aaa目录250Directory successfully changed.

ftp>pwd        # 查看当前所在的ftp目录257 "/aaa"ftp>ls227 Entering Passive Mode (127,0,0,1,88,202).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 09:01aaa1-rw-r--r-- 1 501 501 0 Sep 05 09:02aaa2226Directory send OK.

ftp>

2.4.查询linux系统信息

1) 查询系统中的文件列表

ftp> ! [linux系统命令] #在ftp服务器中执行系统命令,之后回到ftp环境中

ftp> ! ls /usr/local/aegis bin cloudmonitor etc games include lib lib64 libexec logs nginx sbin share src

2)切换linux中的工作目录

ftp> lcd /tmp/ #在ftp服务器中切换本地工作目录(登陆ftp前的系统中的目录),可以tab补全

Local directory now /tmp

2.5.下载上传文件或目录

1)创建和删除ftp目录

ftp>mkdir ccc257 "/aaa/ccc"created

ftp>ls227 Entering Passive Mode (127,0,0,1,194,152).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 09:01aaa1-rw-r--r-- 1 501 501 0 Sep 05 09:02aaa2

drwxr-xr-x 2 501 501 4096 Sep 05 09:06ccc226Directory send OK.

ftp>rmdir ccc250Remove directory operation successful.

ftp>ls227 Entering Passive Mode (127,0,0,1,214,114).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 09:01aaa1-rw-r--r-- 1 501 501 0 Sep 05 09:02aaa2226 Directory send OK.

2)下载ftp的文件

# 下载单个文件

ftp>!pwd     # 查看当前所在的系统工作目录/tmp

ftp>ls227 Entering Passive Mode (127,0,0,1,223,180).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 09:01aaa1-rw-r--r-- 1 501 501 0 Sep 05 09:02aaa2226Directory send OK.

ftp>get aaa1    # 下载aaa1文件

local: aaa1 remote: aaa1227 Entering Passive Mode (127,0,0,1,33,232).150 Opening BINARY mode data connection foraaa1 (0 bytes).226Transfer complete.

ftp>!ls

aaa1

ftp>get aaa2 aaa3    # 下载aaa2文件,并命名为aaa3

local: aaa3 remote: aaa2227 Entering Passive Mode (127,0,0,1,171,86).150 Opening BINARY mode data connection foraaa2 (0 bytes).226Transfer complete.

ftp>!ls          # 查看,下载成功

aaa1 aaa3

# 下载多个文件

ftp>mget aaa1 aaa2

mget aaa1? y227 Entering Passive Mode (127,0,0,1,83,114).150 Opening BINARY mode data connection foraaa1 (0 bytes).226Transfer complete.

mget aaa2? y227 Entering Passive Mode (127,0,0,1,217,121).150 Opening BINARY mode data connection foraaa2 (0 bytes).226Transfer complete.

ftp> !ls -l

total1532

-rw-r--r-- 1 root root 0 Sep 5 17:20aaa1    # 可以看到文件创建时间已经更改-rw-r--r-- 1 root root 0 Sep 5 17:20aaa2-rw-r--r-- 1 root root 0 Sep 5 17:14 aaa3

3)上传文件

# 上传单个文件

# 创建测试文件

[root@ftpsrv tmp]#touch ddd1

[root@ftpsrv tmp]#touch ddd2

[root@ftpsrv tmp]#ll

total 1532

-rw-r--r-- 1 root root 0 Sep 5 17:20aaa1-rw-r--r-- 1 root root 0 Sep 5 17:20aaa2-rw-r--r-- 1 root root 0 Sep 5 17:14aaa3-rw-r--r-- 1 root root 0 Sep 5 17:23ddd1-rw-r--r-- 1 root root 0 Sep 5 17:23 ddd2

# 上传

ftp>put ddd1       # 上传单个文件,可以tab补全

local: ddd1 remote: ddd1227 Entering Passive Mode (127,0,0,1,69,10).150Ok to send data.226Transfer complete.

ftp>put ddd1 eee1    # 上传单个文件并改名

local: ddd1 remote: eee1227 Entering Passive Mode (127,0,0,1,243,160).150Ok to send data.226Transfer complete.

ftp>ls227 Entering Passive Mode (127,0,0,1,234,62).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 09:01aaa1-rw-r--r-- 1 501 501 0 Sep 05 09:02aaa2

drwxr-xr-x 2 501 501 4096 Sep 05 09:18bbb-rw-r--r-- 1 501 501 0 Sep 05 09:23ddd1-rw-r--r-- 1 501 501 0 Sep 05 09:23eee1226 Directory send OK

# 上传多个文件

ftp>mput ddd1 ddd2

mput ddd1? y227 Entering Passive Mode (127,0,0,1,92,11).150Ok to send data.226Transfer complete.

mput ddd2? y227 Entering Passive Mode (127,0,0,1,66,108).150Ok to send data.226Transfer complete.

ftp>ls227 Entering Passive Mode (127,0,0,1,191,91).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 09:01aaa1-rw-r--r-- 1 501 501 0 Sep 05 09:02aaa2

drwxr-xr-x 2 501 501 4096 Sep 05 09:18bbb-rw-r--r-- 1 501 501 0 Sep 05 09:27ddd1    # 查看修改时间可以确认已经上传成功-rw-r--r-- 1 501 501 0 Sep 05 09:27ddd2-rw-r--r-- 1 501 501 0 Sep 05 09:23eee1226 Directory send OK.

2.6.ftp文件目录操作

1)修改ftp文件名

ftp>rename aaa1 qqq1350 Ready forRNTO.250Rename successful.

ftp>ls227 Entering Passive Mode (127,0,0,1,29,54).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 17:02aaa2

drwxr-xr-x 2 501 501 4096 Sep 05 17:18bbb-rw-r--r-- 1 501 501 0 Sep 05 17:27ddd1-rw-r--r-- 1 501 501 0 Sep 05 17:27ddd2-rw-r--r-- 1 501 501 0 Sep 05 17:23eee1-rw-r--r-- 1 501 501 0 Sep 05 17:37fff-rw-r--r-- 1 501 501 0 Sep 05 17:01qqq1    # 修改后的文件名226 Directory send OK.

2)删除ftp文件

ftp>delete aaa2    # 删除aaa2文件250Delete operation successful.

ftp>ls227 Entering Passive Mode (127,0,0,1,138,61).150Here comes the directory listing.

drwxr-xr-x 2 501 501 4096 Sep 05 17:18bbb-rw-r--r-- 1 501 501 0 Sep 05 17:27ddd1-rw-r--r-- 1 501 501 0 Sep 05 17:27ddd2-rw-r--r-- 1 501 501 0 Sep 05 17:23eee1-rw-r--r-- 1 501 501 0 Sep 05 17:37fff-rw-r--r-- 1 501 501 0 Sep 05 17:01qqq1226 Directory send OK.

# 删除多个ftp文件

ftp>mdelete ddd1 ddd2 eee1

mdelete ddd1? y250Delete operation successful.

mdelete ddd2? y250Delete operation successful.

mdelete eee1? y250Delete operation successful.

ftp>ls227 Entering Passive Mode (127,0,0,1,166,205).150Here comes the directory listing.

drwxr-xr-x 2 501 501 4096 Sep 05 17:18bbb-rw-r--r-- 1 501 501 0 Sep 05 17:37fff-rw-r--r-- 1 501 501 0 Sep 05 17:01qqq1226 Directory send OK.

3)删除ftp目录

ftp>rmdir bbb    # 删除bbb目录250Remove directory operation successful.

ftp>ls227 Entering Passive Mode (127,0,0,1,143,198).150Here comes the directory listing.-rw-r--r-- 1 501 501 0 Sep 05 17:37fff-rw-r--r-- 1 501 501 0 Sep 05 17:01qqq1226 Directory send OK.

2.7.其他ftp命令

1)切换传输模式

ftp>ascii       # 切换为ascii模式200Switching to ASCII mode.

ftp>bin        # 切换为二进制模式,默认登陆就是二进制传输模式200 Switching to Binary mode.

2)关闭和重连ftp

ftp>close      # 断开ftp的连接221Goodbye.

ftp>ls        # 可以看出,无法显示ftp服务器的文件列表

Not connected.

ftp> open 127.0.0.1 21    # 重新连接ftp服务器Connected to127.0.0.1 (127.0.0.1).220 (vsFTPd 2.2.2)

Name (127.0.0.1:root): admin     # 使用admin登陆ftp331Please specify the password.

Password:230Login successful.

Remote system typeisUNIX.

Using binary mode to transfer files.

ftp>ls        # 可以再次查看ftp服务器的文件列表227 Entering Passive Mode (127,0,0,1,227,247).150Here comes the directory listing.

drwxr-xr-x 2 501 501 4096 Sep 05 17:47aaa

drwxr-xr-x 2 501 501 4096 Sep 05 16:59bbb226Directory send OK.

3) 退出ftp会话

ftp>quit    # 也可以使用bye和exit221Goodbye.

[root@ftpsrv vsftpd]#

========= 完毕,呵呵呵呵 =========

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值