ftp(file transfer protocol)
成都創(chuàng)新互聯(lián)長期為成百上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為同仁企業(yè)提供專業(yè)的成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站,同仁網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
功能說明:設(shè)置文件系統(tǒng)相關(guān)功能。
語法:ftp [-dignv][主機(jī)名稱或IP地址]
補(bǔ)充說明:FTP是ARPANet的標(biāo)準(zhǔn)文件傳輸協(xié)議,該網(wǎng)絡(luò)就是現(xiàn)今Internet的前身。
參數(shù): 《Linux就該這么學(xué)》
-d 詳細(xì)顯示指令執(zhí)行過程,便于排錯(cuò)或分析程序執(zhí)行的情形。
-i 關(guān)閉互動(dòng)模式,不詢問任何問題。
-g 關(guān)閉本地主機(jī)文件名稱支持特殊字符的擴(kuò)充特性。
-n 不使用自動(dòng)登陸。
-v 顯示指令執(zhí)行過程。
1. 連接ftp服務(wù)器
格式:ftp [hostname| ip-address]
a)在linux命令行下輸入:
ftp 192.168.1.1
b)服務(wù)器詢問你用戶名和密碼,分別輸入用戶名和相應(yīng)密碼,待認(rèn)證通過即可。
c)也可以先輸入ftp
ftp
d)然后在輸入要連接的IP
ftpopen 192.168.1.1
2. 下載文件
下載文件通常用get和mget這兩條命令。
a) get
格式:get [remote-file] [local-file]
將文件從遠(yuǎn)端主機(jī)中傳送至本地主機(jī)中。
如要獲取遠(yuǎn)程服務(wù)器上/usr/your/1.htm,則
ftp get /usr/your/1.htm 1.htm (回車)
b) mget
格式:mget [remote-files]
從遠(yuǎn)端主機(jī)接收一批文件至本地主機(jī)。
如要獲取服務(wù)器上/usr/your/下的所有文件,則
ftp cd /usr/your/
ftp mget *.* (回車)
此時(shí)每下載一個(gè)文件,都會有提示。如果要除掉提示,則在mget *.* 命令前先執(zhí)行:prompt off
注意:文件都下載到了linux主機(jī)的當(dāng)前目錄下。比如,在 /usr/my下運(yùn)行的ftp命令,則文件都下載到了/usr/my下。
3.上傳文件
a) put
格式:put local-file [remote-file]
將本地一個(gè)文件傳送至遠(yuǎn)端主機(jī)中。
如要把本地的1.htm傳送到遠(yuǎn)端主機(jī)/usr/your,并改名為2.htm
ftp put 1.htm /usr/your/2.htm (回車)
b) mput
格式:mput local-files
將本地主機(jī)中一批文件傳送至遠(yuǎn)端主機(jī)。
如要把本地當(dāng)前目錄下所有html文件上傳到服務(wù)器/usr/your/ 下
ftp cd /usr/your (回車)
ftp mput *.htm?。ɑ剀嚕?/p>
FTP設(shè)置開機(jī)自動(dòng)運(yùn)行:chkconfig vsftpd on
關(guān)閉FTP開機(jī)自動(dòng)運(yùn)行:chkconfig vsftpd off
查看所有服務(wù)開啟自動(dòng)運(yùn)行的情況:chkconfig --list
啟動(dòng)FTP服務(wù):service vsftpd start
停止FTP服務(wù):service vsftpd stop
重啟FTP服務(wù):service vsftpd restart
1.Linux下啟動(dòng)ftp
2.連接FTP
3.進(jìn)入FTP目錄
4.查看目錄文件數(shù)
ls -l 普通文件就是以 - 開頭,文件夾以 d 開頭,grep 后面接正則表達(dá)式:^- 以 - 開頭的匹配。
擴(kuò)展資料:
1.查看當(dāng)前目錄下的文件數(shù)量(不包含子目錄中的文件):
ls -l|grep "^-"| wc -l
2. 查看當(dāng)前目錄下的文件數(shù)量(包含子目錄中的文件):
ls -lR|grep "^-"| wc -l
3.查看當(dāng)前目錄下的文件夾目錄個(gè)數(shù),(不包含子目錄中的目錄):
ls -l|grep "^d"| wc -l
4.查詢當(dāng)前路徑下的指定前綴名的目錄下的所有文件數(shù)量 例如:統(tǒng)計(jì)所有以“20161124”開頭的目錄下的全部文件數(shù)量:
ls -lR 20161124*/|grep "^-"| wc -l
Linux之ftp命令使用方法及案例
Example 1:登陸
[root@iZ25ja2kaemZ ~]# ftp 121.199.5.52
Connected to 121.199.5.52 (121.199.5.52).
220 Microsoft FTP Service
Name (121.199.5.52:root): baitongsj
331 User name okay, need password.
Password:
230 User logged in, proceed.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp ll
?Invalid command
ftp
Example2:dir,cd?,quit 命令用法
ftp dir ./app
227 Entering Passive Mode (121,199,5,52,128,234)
150 Opening ASCII mode data connection for /bin/ls.
total 0
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:26 .
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:26 ..
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:24 Common
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:24 Conf
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:19 Lang
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:23 Lib
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:26 Runtime
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:35 Tpl
226 Transfer complete.
ftp cd base
250 Directory changed to /crms/Base
ftp dir
227 Entering Passive Mode (121,199,5,52,128,235)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:18 .
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:18 ..
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:12 Common
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:13 Conf
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:17 Extend
-rw-rw-rw-?? 1 user???? group??????? 1854 Jan 18? 2016 LICENSE.txt
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:17 Lang
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:17 Lib
-rw-rw-rw-?? 1 user???? group??????? 5600 Jan 18? 2016 README.txt
-rw-rw-rw-?? 1 user???? group??????? 1568 Jan 18? 2016 ThinkPHP.php
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:18 Tpl
-rw-rw-rw-?? 1 user???? group??????? 7396 Jan 18? 2016 logo.png
226 Transfer complete.
ftp quie
?Invalid command
ftp quit
221 Goodbye!
[root@iZ25ja2kaemZ ~]#
example3:幫助文件
ftp help
Commands may be abbreviated.? Commands are:
!?????????????? debug?????????? mdir??????????? sendport??????? site
$?????????????? dir???????????? mget??????????? put???????????? size
account???????? disconnect????? mkdir?????????? pwd???????????? status
append????????? exit??????????? mls???????????? quit??????????? struct
ascii?????????? form??????????? mode??????????? quote?????????? system
bell??????????? get???????????? modtime???????? recv??????????? sunique
binary????????? glob??????????? mput??????????? reget?????????? tenex
bye???????????? hash??????????? newer?????????? rstatus???????? tick
case??????????? help??????????? nmap??????????? rhelp?????????? trace
cd????????????? idle??????????? nlist?????????? rename????????? type
cdup??????????? image?????????? ntrans????????? reset?????????? user
chmod?????????? lcd???????????? open??????????? restart???????? umask
close?????????? ls????????????? prompt????????? rmdir?????????? verbose
cr????????????? macdef????????? passive???????? runique???????? ?
delete????????? mdelete???????? proxy?????????? send
ftp help dir
dir???????????? list contents of remote directory
ftp help mdir
mdir??????????? list contents of multiple remote directories
ftp
example4:重命名文件
ftp dir
227 Entering Passive Mode (121,199,5,52,128,234)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 .
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 ..
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:39 Install
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:36 appImg
drw-rw-rw-?? 1 user???? group?????????? 0 Nov 11 11:08 css
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:37 excelmodel
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 file
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:37 ico
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:38 img
drw-rw-rw-?? 1 user???? group?????????? 0 Nov 11 11:11 js
-rw-rw-rw-?? 1 user???? group?????????? 3 Oct 25 15:56 ni.txt
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 sound
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 sql
226 Transfer complete.
ftp rename ni.txt ss
350 File or directory exists, ready for destination name
250 RNTO command successful.
ftp dir
227 Entering Passive Mode (121,199,5,52,128,235)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw-?? 1 user???? group?????????? 0 Nov 16 16:57 .
drw-rw-rw-?? 1 user???? group?????????? 0 Nov 16 16:57 ..
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:39 Install
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:36 appImg
drw-rw-rw-?? 1 user???? group?????????? 0 Nov 11 11:08 css
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:37 excelmodel
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 file
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:37 ico
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:38 img
drw-rw-rw-?? 1 user???? group?????????? 0 Nov 11 11:11 js
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 sound
drw-rw-rw-?? 1 user???? group?????????? 0 Nov? 9 18:46 sql
-rw-rw-rw-?? 1 user???? group?????????? 3 Oct 25 15:56 ss
226 Transfer complete.
example5 :格式 get [remote-file] [local-file],將文件從遠(yuǎn)端主機(jī)中傳送至本地主機(jī)中,如要獲取服務(wù)器上\rose\1.bmp,則? ftp get /rose/1.bmp??? /tmp/1.bmp (回車),必須給出第二個(gè)參數(shù),否則會復(fù)制失敗,登錄后執(zhí)行:
ftp get robots.txt /tmp/
local: /tmp/ remote: robots.txt
227 Entering Passive Mode (121,199,5,52,128,233)
150 Opening BINARY mode data connection for robots.txt (26 Bytes).
local: /tmp/: Is a directory
226 Transfer complete.
226 ABOR command successful.
ftp
example 6:lcd 命令
ftp lcd ..
Local directory now /
ftp lcd /tmp/flower
Local directory now /tmp/flower
example 7: put命令
格式:put local-file [remote-file]
將本地一個(gè)文件傳送至遠(yuǎn)端主機(jī)中.
如要把本地的1.bmp傳送到遠(yuǎn)端主機(jī)e:\rose,并改名為333.bmp
ftp put 1.bmp /rose/333.bmp (回車)
ftp put /tmp/tt.txt ./nihaol.txt
local: /tmp/tt.txt remote: ./nihaol.txt
227 Entering Passive Mode (121,199,5,52,128,232)
150 Opening BINARY mode data connection for nihaol.txt.
226 Transfer complete.
5 bytes sent in 2.6e-05 secs (192.31 Kbytes/sec)
example 8: mput命令
格式:mput local-files
將本地主機(jī)中一批文件傳送至遠(yuǎn)端主機(jī).
如要把本地當(dāng)前目錄下所有bmp文件上傳到服務(wù)器e:\rose 下
ftp cd /rose (回車)
ftp mput *.bmp?。ɑ剀嚕?/p>
注意:上傳文件都來自于主機(jī)的當(dāng)前目錄下。比如,在 /root/test下運(yùn)行的ftp命令,則只有在/root/test下的文件linux才會 上傳到服務(wù)器e:\rose 下