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操作命令的更多相关文章

  1. linux下常用FTP命令

    linux下常用FTP命令 1. 连接ftp服务器 1. 连接ftp服务器格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1b)服 ...

  2. linux下常用FTP命令 上传下载文件【转】

    1. 连接ftp服务器 格式:ftp [hostname| ip-address]a)在linux命令行下输入: ftp 192.168.1.1 b)服务器询问你用户名和密码,分别输入用户名和相应密码 ...

  3. linux下常用命令备忘

    转自:Linux 命令集锦 linux下查看监听端口对应的进程 # lsof -i:9000 # lsof -Pnl +M -i4 如果退格键变成了:"^h". 终端连接unix删 ...

  4. linux下常用关机命令

    linux下常用的关机命令有:shutdown.halt.poweroff.init:重启命令有:reboot.下面本文就主要介绍一些常用的关机命令以及各种关机命令之间的区别和具体用法. 首先来看一下 ...

  5. Linux 下常用解压命令(转载)

    Linux下常用文件解压(包括rpm.deb包) Linux下怎么解后缀名是gzip的文件?1.以.a为扩展名的文件:#tar xv file.a2.以.z为扩展名的文件:#uncompress fi ...

  6. Linux 下常用命令

    linux 下常用命令: 1.删除文件命令为 rm 2.创建目录的命令是:mkdir 3.删除目录的命令是rmdir(空目录) 4.切换到root帐号:su 5.查看所有进程:ps -aux 6.杀死 ...

  7. linux下常用语言的语法检查插件整理

    linux下常用语言的语法检查插件 可以结合vim语法检查插件syntastic使用,具体请参考syntastic使用说明 如php,sql,json,css,js,html,shell,c等语法插件 ...

  8. MongoDB在Linux下常用优化设置

    MongoDB在Linux下常用优化设置 以下是一些MongoDB推荐的常用优化设置.在生产环境下选取合适的参数值,例如预读值和默认文件描述符数目等,会对系统性能有很大的影响. 1.关闭数据库文件的 ...

  9. linux下常用的日志分析命令

    linux下常用的日志分析命令   本文介绍下,在linux中常用的一些分析日志的命令行或脚本,有需要的朋友参考下.     形如下面这样的access.log日志内容: 211.123.23.133 ...

随机推荐

  1. linux设置端口转发(一键设置)

    linux设置端口转发 #下载rinetd程序并进入文件夹 wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xv ...

  2. Python -- Scrapy 架构概览

    架构概览 本文档介绍了Scrapy架构及其组件之间的交互. 概述 接下来的图表展现了Scrapy的架构,包括组件及在系统中发生的数据流的概览(绿色箭头所示). 下面对每个组件都做了简单介绍,并给出了详 ...

  3. webpack和tree shaking和rollup

    http://blog.csdn.net/haodawang/article/details/77199980 tree shaking只对es模块生效,在打包tyscript模块是要使用tsc编译器 ...

  4. spring boot 日志文件配置(logback-spring.xml)亲测可用!

    问题描述:如何配置springboot项目,通过日志配置,使之输出自定义日志. 详细文章:https://blog.csdn.net/gebitan505/article/details/701421 ...

  5. CoderForce 148D-Bag of mice (概率DP求概率)

    题目大意:美女与野兽在玩画鸽子的游戏.鸽子在用黑布遮住的笼子里,白色的有w只,黑色的有b只,每次拿出一只作画,谁先画到白色的鸽子谁就赢.美女首先画,因为野兽太丑,它每次画的时候都会吓跑一只鸽子,所有出 ...

  6. 最小生成树(模板 prim)

    Description 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可).现得到城镇道路统计表, 表中列出了任意两城镇间修建道路 ...

  7. 记一次使用utl_http方法调用接口,报字符或值错误

    背景:ebs系统和其他系统通过utl_http包调用接口,使用log方法记录日志. 某次调用接口,执行到记录日志行报字符或值错误. 查找原因,发现是p_str的长度超过的32767的限制. 解决办法: ...

  8. MyBatis Generator自动创建代码

    MyBatis Generator自动创建代码 1.首先在eclipse上安装mybatis插件 2.创建一个mavenWeb项目. 3.在resource中写入一个xml,一定要与我得同名 < ...

  9. zk客户端的ClientCnxn类

    ClientCnxn是客户端的类:该类管理zk客户端的socket io,维持一个可用服务器的列表. //ClientCnxn类 private final LinkedList<Packet& ...

  10. xrat CC特征

    ["6", 11818669.0, 8326.0, 599.75, 19705.992496873696, 13.882451021258857, 0.07203338938265 ...