Linux终端访问FTP及上传下载⽂件
今天同事问我⼀个问题,在Linux 下访问FTP,并将⽂件上传上去。 我之前⼀直是⽤WinSCP⼯具的。 先将⽂件从linux copy到windows 下,然后在传到ftp上。 google ⼀下。 ⽅法也⽐较简单。 这⾥只讨论通过终端来连接,因为也可以通过IE 或者其他⼯具。
1. Linux 终端连接FTP
[oracle@Dave ~]$ ftp 10.85.7.97
Connected to 10.85.7.97.
220 Serv-U FTP Server v6.4 for
500 'AUTH': command not understood.
500 'AUTH': command not understood.
KERBEROS_V4 rejected as an authentication type
Name (10.85.7.97:oracle): super
331 User name okay, need password.
Password: -- Linux 的密码是不回显的
230 User logged in, proceed.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
如果FTP 允许匿名⽤户,那么⽤户名要输⼊anonymous,密码任意。 不能直接敲回车。
2. 查看FTP 命令
ftp> ?
Commands may be abbreviated. Commands are:
! cr mdir proxy send
$ delete mget sendport site
account debug mkdir put size
append dir mls pwd status
ascii disconnect mode quit struct
bell form modtime quote system
binary get mput recv sunique
bye glob newer reget tenex
case hash nmap rstatus trace
ccc help nlist rhelp type
cd idle ntrans rename user
cdup image open reset umask
chmod lcd passive restart verbose
clear ls private rmdir ?
close macdef prompt runique
cprotect mdelete protect safe
可以通过help command 查看每个命令的说明
ftp> help put
put send one file
ftp> help mput
mput send multiple files
3. 上传⽂件
Put命令:格式:put local-file [remote-file] 将⼀个⽂件上传到ftp
Mput命令:格式:mput local-files 将本地主机中⼀批⽂件传送⾄远端主机.
注意:mput命令只能将当前本地⽬录下的⽂件上传到FTP上的当前⽬录。⽐如,在 /root/dave下运⾏的ftp命令,则只有在/root/dave下的⽂件linux才会上传到服务器上的当前⽬录下。
Put 代码⽰例:
ftp> pwd -- 显⽰FTP上当前路径
257 "/" is current directory.
ftp> ls -- 显⽰当前⽬录下的⽂件
227 Entering Passive Mode (10,85,7,97,16,141)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw- 1 user group 0 Aug 17 16:11 .
drw-rw-rw- 1 user group 0 Aug 17 16:11 ..
-rw-rw-rw- 1 user group 1433088 Feb 5 2010 ASPAJAXExtSetup_PConline_PConline.msi
-rw-rw-rw- 1 user group 197626837 Mar 8 10:00 DelphiV7.0.zip
drw-rw-rw- 1 user group 0 Jul 9 10:17 HHT
-rw-rw-rw- 1 user group 9235148 Dec 24 2009 Install_HSKey_
-rw-rw-rw- 1 user group 47316992 May 27 16:38 Release_4.rar
ftp> mkdir Dave -- 创建⽂件夹Dave
257 "/Dave" directory created.
ftp> cd Dave -- 进⼊⽂件夹Dave
250 Directory changed to /Dave
ftp> pwd -- 显⽰当前⽬录
257 "/Dave" is current directory.
ftp> lcd -- 显⽰当前本地的路径,我们可以将这个路径下的这个⽂件上传到FTP服务器的相关位置Local directory now /home/oracle
ftp> ! -- 退出当前的窗⼝,返回Linux 终端,当我们退出终端的时候,⼜会返回到FTP上。[oracle@Dave ~]$ ls -- 显⽰当前⽬录下的⽂件
dead.letter scripts sqlnet.log
[oracle@Dave ~]$ vi Dave -- 创建⽂件 Dave
[oracle@Dave ~]$ vi DBA -- 创建⽂件 DBA
[oracle@Dave ~]$ ls -- 显⽰⽂件夹⾥的内容,等会我们将这些⽂件copy到FTP上
Dave DBA dead.letter scripts sqlnet.log
[oracle@Dave ~]$ exit -- 退出终端,返回FTP命令⾏
exit
ftp> lcd
Local directory now /home/oracle
ftp> put DBA DBA -- 将刚才创建的⽂件DBA 上传到ftp的当前⽬录上并命名为DBA。
local: DBA remote: DBA
227 Entering Passive Mode (10,85,7,97,16,156)
150 Opening BINARY mode data connection for DBA.
226 Transfer complete.
5 bytes sent in 3.3e-05 seconds (1.5e+02 Kbytes/s)
ftp> put DBA /Dave/SFDBA -- 将刚才创建的⽂件DBA 上传到ftp的当前⽬录上并重命名为SFDBA。local: DBA remote: /Dave/SFDBA
227 Entering Passive Mode (10,85,7,97,16,158)
150 Opening BINARY mode data connection for SFDBA.
226 Transfer complete.
5 bytes sent in 1.8e-05 seconds (2.7e+02 Kbytes/s)
ftp> put /home/oracle/DBA /test/SFDBA
local: /home/oracle/DBA remote: /test/SFDBA
227 Entering Passive Mode (10,85,7,97,16,163)
150 Opening BINARY mode data connection for SFDBA.
226 Transfer complete.
5 bytes sent in 2.2e-05 seconds (2.2e+02 Kbytes/s)
ftp> cd test
250 Directory changed to /test
ftp> ls
227 Entering Passive Mode (10,85,7,97,16,169)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw- 1 user group 0 Aug 17 17:11 .
drw-rw-rw- 1 user group 0 Aug 17 17:11 ..
-rw-rw-rw- 1 user group 5 Aug 17 17:11 SFDBA
-rw-rw-rw- 1 user group 5508 Aug 17 16:21 sqlnet.log 226 Transfer complete.
Mput ⽰例代码:
linux查看当前文件夹内容ftp> cd Dave
250 Directory changed to /Dave
ftp> mput *
mput ? -- 这⾥每个⽂件都要确认,按回车键就可以了
227 Entering Passive Mode (10,85,7,97,16,196)
150 Opening BINARY mode data connection for
226 Transfer complete.
712 bytes sent in 2.9e-05 seconds (2.4e+04 Kbytes/s)
mput alert_newccs.hist?
227 Entering Passive Mode (10,85,7,97,16,197)
150 Opening BINARY mode data connection for alert_newccs.hist. 226 Transfer complete.
9321666 bytes sent in 0.78 seconds (1.2e+04 Kbytes/s)
mput alert_newccs.log?
227 Entering Passive Mode (10,85,7,97,16,198)
150 Opening BINARY mode data connection for alert_newccs.log. 226 Transfer complete.
21707 bytes sent in 0.0014 seconds (1.5e+04 Kbytes/s)
ftp> ls -- 显⽰⽬录下的⽂件
227 Entering Passive Mode (10,85,7,97,16,217)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw- 1 user group 0 Aug 17 17:22 .
drw-rw-rw- 1 user group 0 Aug 17 17:22 ..
-rw-rw-rw- 1 user group 5 Aug 17 17:09 SFDBA
-rw-rw-rw- 1 user group 712 Aug 17 17:21
-rw-rw-rw- 1 user group 9321666 Aug 17 17:21 alert_newccs.hist
-rw-rw-rw- 1 user group 21707 Aug 17 17:21 alert_newccs.log
226 Transfer complete.
ftp> delete SFDBA --删除SFDBA ⽂件
250 DELE command successful.
ftp> mdelete a* -- 批量删除⽂件
mdelete ? -- 每个⽂件都要确认
250 DELE command successful.
mdelete alert_newccs.hist?
250 DELE command successful.
mdelete alert_newccs.log?
250 DELE command successful.
4. 下载⽂件
同样也有2个命令: get 和 mget。 Mget ⽤户批量下载。
格式:get [remote-file] [local-file]
mget [remote-files]
同样,mget 是将⽂件下载到本地的当前⽬录下。
Get ⽰例:
ftp> get /test/SFDBA /home/SFDBA
local: /home/SFDBA remote: /test/SFDBA
local: /home/SFDBA: Permission denied --Linux对权限控制的很严格,下载的时候是否有对应⽂件夹的写权限ftp> get /test/SFDBA /home/oracle/SFDBA
local: /home/oracle/SFDBA remote: /test/SFDBA
227 Entering Passive Mode (10,85,7,97,17,0)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论