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]#
========= 完畢,呵呵呵呵 =========
