Linux下常用的ftp操作命令

摘要:
[Linux system command]#在ftp服务器中执行系统命令,然后返回ftp环境ftp˃!Ls/usr/local/aedisbincloudmonitorcgameincludeblib64libexeclogsginxsbinsharesrc2)切换Linux ftp中的工作目录˃lcd/tmp/#切换ftp服务器中的本地工作目录,您可以使用/tmp2.5选项卡完成本地目录。下载和上传文件或目录1)创建和删除ftp目录ftp˃mkdircc257“/aaa/ccc”createdftp˃ls227进入被动模式。150以下是目录列表-rw-r-r--15015010九月0509:01aaa1-rw-r---r--150150109九月0509:02aaa2drwxr-xr-x25015014096九月0509:06ccc226目录发送OK。ftp˃rmdirccc250删除目录操作成功。ftp˃ls227进入被动模式。150以下是董事列表。-rw-r--1501502010九月0509:01 aaa1-rv-r--15015015010九月10509:02aa2226目录发送OK。2) 下载ftp文件#下载单个文件ftp˃!Pwd#查看当前系统的工作目录/tmpftp˃ls227EnteringPassiveMode。150以下是董事名单rw-r--r-15015010Sep0509:01aaa1-rw-r-15015010 Sep0509:02aaa2226目录sendOK Ftp˃getaaa1#下载aaa1文件local:aaa1remote:aaa1227进入被动模式。150打开BINARY模式数据连接以完成aa1.226传输ftp˃!Lsaaa1ftp˃getaaa2aa3#下载aaa2文件并将其命名为aaa3local:aa3remote:aa2227进入被动模式。150打开BINARY模式数据连接以完成2.226传输。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): nice
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

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

2.ftp子命令

2.1.帮助命令

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

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

ftp> dir
227 Entering Passive Mode (127,0,0,1,44,241).
150 Here comes the directory listing.
drwxr-xr-x    2 501      501          4096 Sep 04 07:18 aaa
drwxr-xr-x    2 501      501          4096 Sep 05 08:59 bbb
226 Directory send OK.
ftp> ls
227 Entering Passive Mode (127,0,0,1,71,215).
150 Here comes the directory listing.
drwxr-xr-x    2 501      501          4096 Sep 04 07:18 aaa
drwxr-xr-x    2 501      501          4096 Sep 05 08:59 bbb
226 Directory send OK.
ftp> 

2.3.切换ftp的目录

ftp> cd aaa      # 切换到ftp的aaa目录
250 Directory successfully changed.
ftp> pwd        # 查看当前所在的ftp目录
257 "/aaa"
ftp> ls
227 Entering Passive Mode (127,0,0,1,88,202).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 09:01 aaa1
-rw-r--r--    1 501      501             0 Sep 05 09:02 aaa2
226 Directory 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 ccc
257 "/aaa/ccc" created
ftp> ls
227 Entering Passive Mode (127,0,0,1,194,152).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 09:01 aaa1
-rw-r--r--    1 501      501             0 Sep 05 09:02 aaa2
drwxr-xr-x    2 501      501          4096 Sep 05 09:06 ccc
226 Directory send OK.
ftp> rmdir ccc
250 Remove directory operation successful.
ftp> ls
227 Entering Passive Mode (127,0,0,1,214,114).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 09:01 aaa1
-rw-r--r--    1 501      501             0 Sep 05 09:02 aaa2
226 Directory send OK.

2)下载ftp的文件

# 下载单个文件

ftp> !pwd        # 查看当前所在的系统工作目录 
/tmp
ftp> ls 
227 Entering Passive Mode (127,0,0,1,223,180).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 09:01 aaa1
-rw-r--r--    1 501      501             0 Sep 05 09:02 aaa2
226 Directory send OK.
ftp> get aaa1    # 下载aaa1文件
local: aaa1 remote: aaa1
227 Entering Passive Mode (127,0,0,1,33,232).
150 Opening BINARY mode data connection for aaa1 (0 bytes).
226 Transfer complete.
ftp> !ls
aaa1
ftp> get aaa2 aaa3    # 下载aaa2文件,并命名为aaa3
local: aaa3 remote: aaa2
227 Entering Passive Mode (127,0,0,1,171,86).
150 Opening BINARY mode data connection for aaa2 (0 bytes).
226 Transfer complete.
ftp> !ls          # 查看,下载成功
aaa1  aaa3

# 下载多个文件

ftp> mget aaa1 aaa2
mget aaa1? y
227 Entering Passive Mode (127,0,0,1,83,114).
150 Opening BINARY mode data connection for aaa1 (0 bytes).
226 Transfer complete.
mget aaa2? y
227 Entering Passive Mode (127,0,0,1,217,121).
150 Opening BINARY mode data connection for aaa2 (0 bytes).
226 Transfer complete.
ftp> !ls -l
total 1532
-rw-r--r-- 1 root root       0 Sep  5 17:20 aaa1    # 可以看到文件创建时间已经更改
-rw-r--r-- 1 root root       0 Sep  5 17:20 aaa2
-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:20 aaa1
-rw-r--r-- 1 root root       0 Sep  5 17:20 aaa2
-rw-r--r-- 1 root root       0 Sep  5 17:14 aaa3
-rw-r--r-- 1 root root       0 Sep  5 17:23 ddd1
-rw-r--r-- 1 root root       0 Sep  5 17:23 ddd2

# 上传

ftp> put ddd1       # 上传单个文件,可以tab补全
local: ddd1 remote: ddd1
227 Entering Passive Mode (127,0,0,1,69,10).
150 Ok to send data.
226 Transfer complete.
ftp> put ddd1 eee1    # 上传单个文件并改名
local: ddd1 remote: eee1
227 Entering Passive Mode (127,0,0,1,243,160).
150 Ok to send data.
226 Transfer complete.
ftp> ls
227 Entering Passive Mode (127,0,0,1,234,62).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 09:01 aaa1
-rw-r--r--    1 501      501             0 Sep 05 09:02 aaa2
drwxr-xr-x    2 501      501          4096 Sep 05 09:18 bbb
-rw-r--r--    1 501      501             0 Sep 05 09:23 ddd1
-rw-r--r--    1 501      501             0 Sep 05 09:23 eee1
226 Directory send OK

# 上传多个文件

ftp> mput ddd1 ddd2 
mput ddd1? y
227 Entering Passive Mode (127,0,0,1,92,11).
150 Ok to send data.
226 Transfer complete.
mput ddd2? y
227 Entering Passive Mode (127,0,0,1,66,108).
150 Ok to send data.
226 Transfer complete.
ftp> ls
227 Entering Passive Mode (127,0,0,1,191,91).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 09:01 aaa1
-rw-r--r--    1 501      501             0 Sep 05 09:02 aaa2
drwxr-xr-x    2 501      501          4096 Sep 05 09:18 bbb
-rw-r--r--    1 501      501             0 Sep 05 09:27 ddd1    # 查看修改时间可以确认已经上传成功
-rw-r--r--    1 501      501             0 Sep 05 09:27 ddd2
-rw-r--r--    1 501      501             0 Sep 05 09:23 eee1
226 Directory send OK.

2.6.ftp文件目录操作

1)修改ftp文件名

ftp> rename aaa1 qqq1
350 Ready for RNTO.
250 Rename successful.
ftp> ls
227 Entering Passive Mode (127,0,0,1,29,54).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 17:02 aaa2
drwxr-xr-x    2 501      501          4096 Sep 05 17:18 bbb
-rw-r--r--    1 501      501             0 Sep 05 17:27 ddd1
-rw-r--r--    1 501      501             0 Sep 05 17:27 ddd2
-rw-r--r--    1 501      501             0 Sep 05 17:23 eee1
-rw-r--r--    1 501      501             0 Sep 05 17:37 fff
-rw-r--r--    1 501      501             0 Sep 05 17:01 qqq1    # 修改后的文件名
226 Directory send OK.

2)删除ftp文件

ftp> delete aaa2    # 删除aaa2文件
250 Delete operation successful.
ftp> ls
227 Entering Passive Mode (127,0,0,1,138,61).
150 Here comes the directory listing.
drwxr-xr-x    2 501      501          4096 Sep 05 17:18 bbb
-rw-r--r--    1 501      501             0 Sep 05 17:27 ddd1
-rw-r--r--    1 501      501             0 Sep 05 17:27 ddd2
-rw-r--r--    1 501      501             0 Sep 05 17:23 eee1
-rw-r--r--    1 501      501             0 Sep 05 17:37 fff
-rw-r--r--    1 501      501             0 Sep 05 17:01 qqq1
226 Directory send OK.

# 删除多个ftp文件

ftp> mdelete ddd1 ddd2 eee1
mdelete ddd1? y
250 Delete operation successful.
mdelete ddd2? y
250 Delete operation successful.
mdelete eee1? y
250 Delete operation successful.
ftp> ls
227 Entering Passive Mode (127,0,0,1,166,205).
150 Here comes the directory listing.
drwxr-xr-x    2 501      501          4096 Sep 05 17:18 bbb
-rw-r--r--    1 501      501             0 Sep 05 17:37 fff
-rw-r--r--    1 501      501             0 Sep 05 17:01 qqq1
226 Directory send OK.

3)删除ftp目录

ftp> rmdir bbb    # 删除bbb目录
250 Remove directory operation successful.
ftp> ls
227 Entering Passive Mode (127,0,0,1,143,198).
150 Here comes the directory listing.
-rw-r--r--    1 501      501             0 Sep 05 17:37 fff
-rw-r--r--    1 501      501             0 Sep 05 17:01 qqq1
226 Directory send OK.

2.7.其他ftp命令

1)切换传输模式

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

2)关闭和重连ftp

ftp> close      # 断开ftp的连接
221 Goodbye.
ftp> ls        # 可以看出,无法显示ftp服务器的文件列表
Not connected.
ftp> open 127.0.0.1 21    # 重新连接ftp服务器
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): admin     # 使用admin登陆ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls        # 可以再次查看ftp服务器的文件列表
227 Entering Passive Mode (127,0,0,1,227,247).
150 Here comes the directory listing.
drwxr-xr-x    2 501      501          4096 Sep 05 17:47 aaa
drwxr-xr-x    2 501      501          4096 Sep 05 16:59 bbb
226 Directory send OK.

3) 退出ftp会话

ftp> quit    # 也可以使用bye和exit
221 Goodbye.
[root@ftpsrv vsftpd]# 

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

免责声明:文章转载自《Linux下常用的ftp操作命令》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇lakka一文带你搞定AOP切面下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Linux初识(转)

 文件系统是linux的一个十分基础的知识,同时也是学习linux的必备知识。     本文将站在一个较高的视图来了解linux的文件系统,主要包括了linux磁盘分区和目录、挂载基本原理、文件存储结构、软链接硬链接、和常见目录的介绍。相信有了这些知识对于深入的学习linux会有一定的帮助。文章例子主要是基于ubuntu发行版。     如有不对之处请大家...

JavaScript 文件操作方法详解

可以通过浏览器在访问者的硬盘上创建文件,因为我开始试了一下真的可以,不信你把下面这段代码COPY到一个HTML文件当中再运行一下! <scriptlanguage="JavaScript"> <!-- varfso=newActiveXObject("Scripting.FileSystemObject"); fso.DeleteFile...

Linux命令集合

批量改名文件 for var in `ls *.bak`;do mv -f "$var" `echo "$var"|sed 's/....$//'`;done //将去除文件名字后面的 .bak for var in `ls *.bak`;do mv -f "$var" `echo "$var"|sed 's/...$/xxx/'`;done /...

Linux wc文件统计

原文链接 linux下如何统计一个目录下的文件个数以及代码总行数的命令知道指定后缀名的文件总个数命令:find . -name "*.cpp" | wc -l知道一个目录下代码总行数以及单个文件行数:find . -name "*.h" | xargs wc -llinux统计文件夹中文件数目第一种方法:ls -l|grep “^-”|wc -lls -l...

VSFTP服务

概述: FTP服务器(File Transfer Protocol Server)是在互联网上提供文件存储和访问服务的计算机,它们依照FTP协议提供服务。 FTP(File Transfer Protocol: 文件传输协议)作用: Internet 上用来传送文件的协议 常见FTP服务器: windows:Serv-U FTP Server L...

FTP协议的粗浅学习--利用wireshark抓包分析相关tcp连接

FTP相关文章: Linux上的ftp服务器 vsftpd 之配置满天飞--设置匿名用户访问(不弹出用户名密码框)以及其他用户可正常上传 ftp服务器Serv-U 设置允许自动创建不存在的目录     一、为什么写这个 昨天遇到个ftp相关的问题,关于ftp匿名访问的。花费了大量的脑细胞后,终于搞定了服务端的配置,现在客户端可以像下图一样,直接在浏览器输...