這里介紹在 Linux shell 中如何使用 ftp 命令。包括如何連接 FTP 服務(wù)器,上傳或下載文件以及創(chuàng)建文件夾。盡管現(xiàn)在有許多不錯(cuò)的 FTP 桌面應(yīng)用,但是在服務(wù)器、SSH、遠(yuǎn)程會(huì)話中命令行 ftp 命令還是有很多應(yīng)用的。比如。需要服務(wù)器從 ftp 倉(cāng)庫(kù)拉取備份。
步驟一:建立FTP連接
想要連接 FTP 服務(wù)器,在命令上中先輸入ftp然后空格跟上 FTP 服務(wù)器的域名 'domain.com' 或者 IP 地址
ftp domain.com
ftp 192.168.0.1
ftp user@ftpdomain.com
注意: 本例中使用匿名服務(wù)器。
替換下面例子中 IP 或域名為你的服務(wù)器地址。
步驟 2: 使用用戶名密碼登錄
絕大多數(shù)的 FTP 服務(wù)器是使用密碼保護(hù)的,因此這些 FTP 服務(wù)器會(huì)詢問(wèn)'username'和'password'.
如果你連接到被稱(chēng)作匿名 FTP 服務(wù)器(LCTT 譯注:即,并不需要你有真實(shí)的用戶信息即可使用的 FTP 服務(wù)器稱(chēng)之為匿名 FTP 服務(wù)器),可以嘗試anonymous作為用戶名以及使用空密碼:
Name: anonymous
Password:
之后,終端會(huì)返回如下的信息
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
表示登錄成功。
步驟 3: 目錄操作
FTP 命令可以列出、移動(dòng)和創(chuàng)建文件夾,如同我們?cè)诒镜厥褂梦覀兊碾娔X一樣。ls可以打印目錄列表,cd可以改變目錄,mkdir可以創(chuàng)建文件夾。
使用安全設(shè)置列出目錄
ftp> ls
服務(wù)器將返回:
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
directory list
....
....
226 Directory send OK.
改變目錄
ftp> cd directory
服務(wù)器將返回:
250 Directory succesfully changed.
步驟 4: 使用 FTP 下載文件
在下載一個(gè)文件之前,我們首先需要使用lcd命令設(shè)定本地接受目錄位置。
lcd /home/user/yourdirectoryname
如果你不指定下載目錄,文件將會(huì)下載到你登錄 FTP 時(shí)候的工作目錄。
現(xiàn)在,我們可以使用命令 get 來(lái)下載文件,比如:
get file
文件會(huì)保存在使用lcd命令設(shè)置的目錄位置。
服務(wù)器返回消息:
local: file remote: file
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for file (xxx bytes).
226 File send OK.
XXX bytes received in x.xx secs (x.xxx MB/s).
使用 put命令上傳文件:
put file
當(dāng)文件不再當(dāng)前本地目錄下的時(shí)候,可以使用絕對(duì)路徑:
put /path/file
同樣,可以上傳多個(gè)文件:
mput *.xls
步驟 6: 關(guān)閉 FTP 連接
bye
exit
quit
任意一個(gè)命令可以斷開(kāi)FTP服務(wù)器連接并返回:
221 Goodbye
需要更多幫助,在使用 ftp 命令連接到服務(wù)器后,可以使用help獲得更多幫助。via: https://www.howtoforge.com/tutorial/how-to-use-ftp-on-the-linux-shell/
案例:從NCBI下載igblast安裝包。
$ftp ftp.ncbi.nih.gov
Connected to ftp.wip.ncbi.nlm.nih.gov.
220-
This warning banner provides privacy and security notices consistent with
applicable federal laws, directives, and other federal guidance for accessing
this Government system, which includes all devices/storage media attached to
this system. This system is provided for Government-authorized use only.
Unauthorized or improper use of this system is prohibited and may result in
disciplinary action and/or civil and criminal penalties. At any time, and for
any lawful Government purpose, the government may monitor, record, and audit
your system usage and/or intercept, search and seize any communication or data
transiting or stored on this system. Therefore, you have no reasonable
expectation of privacy. Any communication or data transiting or stored on this
system may be disclosed or used for any lawful Government purpose.
220 FTP Server ready.
Name (ftp.ncbi.nih.gov:dushiyi): anonymous
上面輸入Name;
331 Anonymous login ok, send your complete email address as your password
Password:
230 Anonymous access granted, restrictions apply
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful
150 Opening BINARY mode data connection for file list
dr-xr-xr-x 4 ftp anonymous 4096 Jul 22 02:48 1000genomes
-r--r--r-- 1 ftp anonymous 107375230976 Nov 17 2017 100GB
-r--r--r-- 1 ftp anonymous 10738466816 Nov 17 2017 10GB
-r--r--r-- 1 ftp anonymous 1074790400 Nov 17 2017 1GB
-r--r--r-- 1 ftp anonymous 53688139776 Nov 17 2017 50GB
-r--r--r-- 1 ftp anonymous 5369757696 Nov 17 2017 5GB
-r--r--r-- 1 ftp anonymous 2037 Oct 12 2017 README.ftp
dr-xr-xr-x 8 ftp anonymous 4096 Feb 8 2016 SampleData
lr--r--r-- 1 ftp anonymous 29 Oct 12 2017 asn1-converters -> toolbox/ncbi_tools/converters
dr-xr-xr-x 12 ftp anonymous 184320 Nov 22 2014 bigwig
dr-xr-xr-x 5 ftp anonymous 4096 Jul 21 15:10 bioproject
dr-xr-xr-x 2 ftp anonymous 4096 Jul 21 09:20 biosample
dr-xr-xr-x 10 ftp anonymous 4096 Jul 22 02:48 blast
dr-xr-xr-x 3 ftp anonymous 4096 Sep 13 2004 cgap
dr-xr-xr-x 4 ftp anonymous 4096 Oct 3 2014 cn3d
dr-xr-xr-x 34 ftp anonymous 4096 Dec 14 2018 dbgap
dr-xr-xr-x 2 ftp anonymous 4096 Sep 21 2017 diffexpIR-notebook
dr-xr-xr-x 12 ftp anonymous 4096 Jul 18 2013 entrez
dr-xr-xr-x 7 ftp anonymous 4096 Oct 13 2011 epigenomics
dr-xr-xr-x 4 ftp anonymous 4096 Sep 19 2017 eqtl
dr-xr-xr-x 6 ftp anonymous 4096 Aug 4 2006 fa2htgs
-r--r--r-- 1 ftp anonymous 3262 Oct 12 2017 favicon.ico
dr-xr-xr-x 13 ftp anonymous 258048 Jul 22 02:48 genbank
dr-xr-xr-x 6 ftp anonymous 4096 Feb 28 2018 gene
dr-xr-xr-x 561 ftp anonymous 45056 Jul 22 02:48 genomes
dr-xr-xr-x 1073741824 ftp anonymous 0 Jul 21 18:22 geo
dr-xr-xr-x 4 ftp anonymous 4096 Jul 22 02:48 giab
dr-xr-xr-x 25 ftp anonymous 4096 Sep 20 2011 hapmap
dr-xr-xr-x 9 ftp anonymous 4096 Jul 2 2018 hmm
dr-xr-xr-x 15 ftp anonymous 4096 Mar 22 15:50 mmdb
dr-xr-xr-x 7 ftp anonymous 86016 Jun 20 18:26 ncbi-asn1
dr-xr-xr-x 2 ftp anonymous 6 Oct 12 2017 nist-immsa
dr-xr-xr-x 3 ftp anonymous 8192 Jul 2 16:32 osiris
dr-xr-xr-x 9 ftp anonymous 4096 Jul 22 02:48 pathogen
dr-xr-xr-x 162 ftp anonymous 8192 Apr 19 16:07 pub
dr-xr-xr-x 28 ftp anonymous 4096 Jul 22 02:48 pubchem
dr-xr-xr-x 21 ftp anonymous 4096 May 13 15:10 pubmed
dr-xr-xr-x 21 ftp anonymous 4096 Jul 12 16:56 refseq
dr-xr-xr-x 57 ftp anonymous 4096 Jul 22 02:48 repository
-r--r--r-- 1 ftp anonymous 26 Oct 12 2017 robots.txt
dr-xr-xr-x 3 ftp anonymous 4096 Jul 22 02:48 seqc
dr-xr-xr-x 6 ftp anonymous 4096 Jun 4 14:50 sequin
dr-xr-xr-x 4 ftp anonymous 4096 Jun 23 2016 sky-cgh
dr-xr-xr-x 8 ftp anonymous 4096 Jul 22 02:48 snp
dr-xr-xr-x 23 ftp anonymous 4096 Jul 22 02:48 sra
dr-xr-xr-x 2 ftp anonymous 4096 Sep 29 2004 tech-reports
dr-xr-xr-x 11 ftp anonymous 4096 Jul 25 2013 toolbox
dr-xr-xr-x 6 ftp anonymous 4096 Sep 5 2018 tpa
dr-xr-xr-x 5 ftp anonymous 4096 Aug 9 2016 variation
226 Transfer complete
上面列出當(dāng)前目錄下內(nèi)容,并且進(jìn)入指定目錄。
ftp> cd blast/executables/igblast/release/
250 CWD command successful
ftp> ls
200 PORT command successful
150 Opening BINARY mode data connection for file list
dr-xr-xr-x 2 ftp anonymous 4096 Nov 1 2018 1.10.0
dr-xr-xr-x 2 ftp anonymous 4096 Nov 1 2018 1.11.0
dr-xr-xr-x 2 ftp anonymous 4096 Nov 29 2018 1.12.0
dr-xr-xr-x 2 ftp anonymous 4096 Mar 7 19:49 1.13.0
dr-xr-xr-x 2 ftp anonymous 4096 Apr 29 16:52 1.14.0
dr-xr-xr-x 2 ftp anonymous 4096 Mar 11 2014 1.3.0
dr-xr-xr-x 2 ftp anonymous 4096 Jul 30 2014 1.4.0
dr-xr-xr-x 2 ftp anonymous 4096 Nov 1 2016 1.5.0
dr-xr-xr-x 2 ftp anonymous 4096 Nov 1 2016 1.6.1
dr-xr-xr-x 2 ftp anonymous 4096 Oct 13 2017 1.7.0
dr-xr-xr-x 2 ftp anonymous 4096 Oct 13 2017 1.8.0
dr-xr-xr-x 2 ftp anonymous 4096 Sep 6 2018 1.9.0
lr--r--r-- 1 ftp anonymous 7 Apr 29 17:40 LATEST -> 1.14.0/
-r--r--r-- 1 ftp anonymous 86 Oct 13 2017 README
dr-xr-xr-x 3 ftp anonymous 4096 Apr 17 16:59 database
-r--r--r-- 1 ftp anonymous 624 Feb 1 2018 edit_imgt_file.pl
dr-xr-xr-x 8 ftp anonymous 4096 Apr 29 2014 internal_data
dr-xr-xr-x 3 ftp anonymous 4096 Apr 29 2014 optional_file
226 Transfer complete
ftp> cd 1.14.0
250 CWD command successful
ftp> ls
200 PORT command successful
150 Opening BINARY mode data connection for file list
-r--r--r-- 1 ftp anonymous 3478 Apr 30 16:15 ChangeLog
-r--r--r-- 1 ftp anonymous 17687750 Apr 29 16:52 ncbi-igblast-1.14.0+.dmg
-r--r--r-- 1 ftp anonymous 59 Apr 29 16:52 ncbi-igblast-1.14.0+.dmg.md5
-r--r--r-- 1 ftp anonymous 14713607 Apr 29 16:52 ncbi-igblast-1.14.0-1.src.rpm
-r--r--r-- 1 ftp anonymous 64 Apr 29 16:52 ncbi-igblast-1.14.0-1.src.rpm.md5
-r--r--r-- 1 ftp anonymous 24002792 Apr 29 16:52 ncbi-igblast-1.14.0-1.x86_64.rpm
-r--r--r-- 1 ftp anonymous 67 Apr 29 16:52 ncbi-igblast-1.14.0-1.x86_64.rpm.md5
-r--r--r-- 1 ftp anonymous 18402750 Apr 29 16:52 ncbi-igblast-1.14.0-src.tar.gz
-r--r--r-- 1 ftp anonymous 65 Apr 29 16:52 ncbi-igblast-1.14.0-src.tar.gz.md5
-r--r--r-- 1 ftp anonymous 22317024 Apr 29 16:52 ncbi-igblast-1.14.0-src.zip
-r--r--r-- 1 ftp anonymous 62 Apr 29 16:52 ncbi-igblast-1.14.0-src.zip.md5
-r--r--r-- 1 ftp anonymous 12628211 Apr 29 16:52 ncbi-igblast-1.14.0-win64.exe
-r--r--r-- 1 ftp anonymous 64 Apr 29 16:52 ncbi-igblast-1.14.0-win64.exe.md5
-r--r--r-- 1 ftp anonymous 40771400 Apr 29 16:52 ncbi-igblast-1.14.0-x64-linux.tar.gz
-r--r--r-- 1 ftp anonymous 71 Apr 29 16:52 ncbi-igblast-1.14.0-x64-linux.tar.gz.md5
-r--r--r-- 1 ftp anonymous 23297125 Apr 29 16:52 ncbi-igblast-1.14.0-x64-macosx.tar.gz
-r--r--r-- 1 ftp anonymous 72 Apr 29 16:52 ncbi-igblast-1.14.0-x64-macosx.tar.gz.md5
-r--r--r-- 1 ftp anonymous 16309449 Apr 29 16:52 ncbi-igblast-1.14.0-x64-win64.tar.gz
-r--r--r-- 1 ftp anonymous 71 Apr 29 16:52 ncbi-igblast-1.14.0-x64-win64.tar.gz.md5
226 Transfer complete
ftp> get ncbi-igblast-1.14.0-x64-linux.tar.gz
local: ncbi-igblast-1.14.0-x64-linux.tar.gz remote: ncbi-igblast-1.14.0-x64-linux.tar.gz
200 PORT command successful
150 Opening BINARY mode data connection for ncbi-igblast-1.14.0-x64-linux.tar.gz (40771400 bytes)
226 Transfer complete
40771400 bytes received in 16.39 secs (2.3726 MB/s)
下載完成。
mget * # 下載所有
lcd #修改下載路徑
prompt off #關(guān)閉