这儿介绍在Linuxshell中怎样使用ftp命令。包括怎样联接FTP服务器,上传或下载文件以及创建文件夹。虽然现今有许多不错的FTP桌面应用,并且在服务器、SSH、远程会话中命令行ftp命令还是有好多应用的。诸如。须要服务器从ftp库房拉取备份。

步骤一:构建FTP联接

想要联接FTP服务器,在命令上中先输入ftp之后空格跟上FTP服务器的域名”或则IP地址

ftp domain.com
ftp 192.168.0.1
ftp user@ftpdomain.com

注意:本例中使用匿名服务器。

替换下边事例中IP或域名为你的服务器地址。

步骤2:使用用户名密码登入

绝大多数的FTP服务器是使用密码保护的,因而这种FTP服务器会寻问’username’和’password’.

假如你联接到被叫做匿名FTP服务器(LCTT评注:即,并不须要你有真实的用户信息即可使用的FTP服务器称之为匿名FTP服务器),可以尝试anonymous作为用户名以及使用空密码:

命令下达_linux下ftp命令_命令下达马上执行的句子

Name: anonymous
Password:

以后,终端会返回如下的信息

230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

表示登陆成功。

步骤3:目录操作

FTP命令可以列举、移动和创建文件夹64位linux,就像我们在本地使用我们的笔记本一样。ls可以复印目录列表,cd可以改变目录linux下ftp命令,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命令设定本地接受目录位置。

linux下ftp命令_命令下达马上执行的句子_命令下达

lcd /home/user/yourdirectoryname

假如你不指定下载目录,文件将会下载到你登入FTP时侯的工作目录。

如今,我们可以使用命令get来下载文件,例如:

getfile

文件会保存在使用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命令上传文件:

putfile

当文件不再当前本地目录下的时侯,可以使用绝对路径:

put/path/file

同样linux下ftp命令,可以上传多个文件:

mput*.xls

步骤6:关掉FTP联接

bye
exit
quit

任意一个命令可以断掉FTP服务器联接并返回:

221 Goodbye

须要更多帮助,在使用ftp命令联接到服务器后,可以使用help获得更多帮助。via:

案例:从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

里面列举当前目录下内容linux重启命令,但是步入指定目录。

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 #关闭

Tagged:
Author

这篇优质的内容由TA贡献而来

刘遄

《Linux就该这么学》书籍作者,RHCA认证架构师,教育学(计算机专业硕士)。

发表回复