今天同事问我一个问题,在 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 WinSock ready...
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 的password是不回显的
230 User logged in, proceed.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
假设 FTP 同意匿名用户,那么 username要输入 anonymous, password随意。 不能直接敲回车。
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 才会上传到server上的当前文件夹下。
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_V1.3.exe
-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 server的相关位置
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 演示样例代码:
ftp> cd Dave
250 Directory changed to /Dave
ftp> mput *
mput alert_log.txt? -- 这里每一个文件都要确认,按回车键就能够了
227 Entering Passive Mode (10,85,7,97,16,196)
150 Opening BINARY mode data connection for alert_log.txt.
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 alert_log.txt
-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 alert_log.txt? -- 每一个文件都要确认
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)
150 Opening BINARY mode data connection for SFDBA (5 Bytes).
226 Transfer complete.
5 bytes received in 6.2e-05 seconds (79 Kbytes/s)
ftp> !
[oracle@Dave bdump]$ cd /home/oracle/
[oracle@Dave ~]$ ls
Dave DBA dead.letter scripts SFDBA sqlnet.log
Mget 演示样例:
ftp> ls
227 Entering Passive Mode (10,85,7,97,17,10)
150 Opening ASCII mode data connection for /bin/ls.
drw-rw-rw- 1 user group 0 Aug 17 17:38 .
drw-rw-rw- 1 user group 0 Aug 17 17:38 ..
-rw-rw-rw- 1 user group 5 Aug 17 17:38 DBA
-rw-rw-rw- 1 user group 12 Aug 17 17:38 Dave
-rw-rw-rw- 1 user group 5 Aug 17 17:11 SFDBA
226 Transfer complete.
ftp> mget *
mget DBA? -- 每一个文件都要确认, 按回车就可以
227 Entering Passive Mode (10,85,7,97,17,12)
150 Opening BINARY mode data connection for DBA (5 Bytes).
226 Transfer complete.
5 bytes received in 8.1e-05 seconds (60 Kbytes/s)
mget Dave?
227 Entering Passive Mode (10,85,7,97,17,13)
150 Opening BINARY mode data connection for Dave (12 Bytes).
226 Transfer complete.
12 bytes received in 8.3e-05 seconds (1.4e+02 Kbytes/s)
mget SFDBA?
227 Entering Passive Mode (10,85,7,97,17,14)
150 Opening BINARY mode data connection for SFDBA (5 Bytes).
226 Transfer complete.
5 bytes received in 9e-05 seconds (54 Kbytes/s)
ftp> !
[oracle@Dave ~]$ ls
Dave DBA dead.letter scripts SFDBA sqlnet.log
说明的地方: FTP 当前文件夹下的文件下载到本地的当前文件夹。
5. 断开 FTP 连接
Bye 命令或者 quit 命令:中断与server的连接。
ftp> bye
221 Goodbye!
以上仅仅是 Linux 终端訪问 ftp 及上传下载的几个简单演示样例。 只是一般这几个应该够用了。其它功能感兴趣的自己研究。
------------------------------------------------------------------------------
Blog : http://blog.csdn.net/tianlesoftware
网上资源: http://tianlesoftware.download.csdn.net
相关视频: http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
DBA1 群: 62697716( 满 ); DBA2 群: 62697977( 满 )
DBA3 群: 63306533; 聊天 群: 40132017