这里介绍在 Linux shell 中如何使用 ftp 命令。包括如何连接 FTP 服务器,上传或下载文件以及创建文件夹。尽管现在有许多不错的 FTP 桌面应用,但是在服务器、SSH、远程会话中命令行 ftp 命令还是有很多应用的。比如。需要服务器从 ftp 仓库拉取备份。
步骤一:建立FTP连接
想要连接 FTP 服务器,在命令上中先输入ftp然后空格跟上 FTP 服务器的域名 'domain.com' 或者 IP 地址
ftp domain.com
ftp 192.168.0.1
ftp user@ftpdomain.com
注意: 本例中使用匿名服务器。
替换下面例子中 IP 或域名为你的服务器地址。
步骤 2: 使用用户名密码登录
绝大多数的 FTP 服务器是使用密码保护的,因此这些 FTP 服务器会询问'username'和'password'.
如果你连接到被称作匿名 FTP 服务器(LCTT 译注:即,并不需要你有真实的用户信息即可使用的 FTP 服务器称之为匿名 FTP 服务器),可以尝试anonymous作为用户名以及使用空密码:
Name: anonymous
Password:
之后,终端会返回如下的信息
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
表示登录成功。
步骤 3: 目录操作
FTP 命令可以列出、移动和创建文件夹,如同我们在本地使用我们的电脑一样。ls可以打印目录列表,cd可以改变目录,mkdir可以创建文件夹。
使用安全设置列出目录
ftp> ls
服务器将返回:
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
directory list
....
....
226 Directory send OK.
改变目录
ftp> cd directory
服务器将返回:
250 Directory succesfully changed.
步骤 4: 使用 FTP 下载文件
在下载一个文件之前,我们首先需要使用lcd命令设定本地接受目录位置。
lcd /home/user/yourdirectoryname
如果你不指定下载目录,文件将会下载到你登录 FTP 时候的工作目录。
现在,我们可以使用命令 get 来下载文件,比如:
get file
文件会保存在使用lcd命令设置的目录位置。
服务器返回消息:
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
当文件不再当前本地目录下的时候,可以使用绝对路径:
put /path/file
同样,可以上传多个文件:
mput *.xls
步骤 6: 关闭 FTP 连接
bye
exit
quit
任意一个命令可以断开FTP服务器连接并返回:
221 Goodbye
需要更多帮助,在使用 ftp 命令连接到服务器后,可以使用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
上面列出当前目录下内容,并且进入指定目录。
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 #关闭
网友评论