ftp 命令

来源:互联网 发布:淘宝快修先生怎么样 编辑:程序博客网 时间:2024/06/05 14:07

#>ftp
ftp>open 172.18.100.42
ftp>lcd /opt/GenEMS    进入本机目录/opt/GenEMS
ftp>mkdir tmp          ftp上创建目录tmp
ftp>cd  /tmp           进入远程ftp目录tmp
ftp>mput *             上传本机目录/opt/GenEMS的文件到ftp的当前目录
ftp>bin                  以二进制传输,文件保持原样

ftp>mget *      从ftp当前目录下载文件到本机目录/opt/GenEMS
ftp>bye



重要命令及相似命令:

 

   (1) ?, help, remotehelp, rhelp:

 

       help       顯示 local 端的命令說明, 若不接命令則顯示所有可用命令.

       ?          相當於 help.e.g. ? cd (Enter)

       rhelp      同 help, 除了他為顯示 remote端.

       remotehelp 相當於 rhelp.

 

   (2) asc (ascii), bin (binary), image, type:

 

       ascii  切換傳輸模式為文字模式.(只能用來傳送 doc, 因為是 7-bit)

       binary 切換傳輸模式為二進位模式. (除文字檔外皆用此模式)

       image  相當於 binary.

       type   讓你更改或顯示目前傳輸模式.

 

   (3) bye, quit:

 

       bye  退離 ftp.

       quit 相當於 bye.

 

   (4) cd, cdup, lcd, pwd, !:

 

 

 

       cd   改變目前工作目錄(change directory). e.g. cd /pub (Enter)

       cdup 回到上一層目錄, 相當於你打 cd .. (Enter)

       lcd  讓你更改或顯示 local端的工作目錄. e.g. lcd /tmp (Enter)

       pwd  顯示目前的工作目錄.(remote 端)

       !    讓你執行 shellcommand. e.g. !ls (Enter)

 

   (5) delete, mdelete, rename:

 

       delete  刪除 remote 端的檔案.

       mdelete 集體(大量)刪除檔案, 需配合萬用字元.

       rename  更改 remote 端的檔案名稱.

 

   (6) get, mget, put, mput, recv, send:

 

       get  抓取(下傳)檔案.

       mget 集體(大量)抓取檔案, 需配合萬用字元. e.g. mget *.gz

       put  丟放(上傳)檔案.

       mput 集體(大量)丟放檔案, 需配合萬用字元.

       recv 相當於 get. (receive)

       send 相當於 put.

 

   (7) hash, prompt, verbose, status, bell:

 

   (7) hash, prompt, verbose, status, bell:

 

       hash    切換 # 字號的出現. 每一個 # 字號表示每傳送了1024/8192 bytes.

       prompt  切換Interactive on/off. e.g. 當 mget * , on/off 確定傳檔.

       verbose 切換所有檔案傳輸過程的顯示.

       status  顯示目前的一些參數.

       bell    切換嗶嗶聲,當指令做完時會發出一聲...beep!

 

   (8) ls, dir, mls, mdir, mkdir, rmdir:

 

       ls    有點像 UNIX 下的 ls (list) 命令.

       dir   相當 ls -l(list -long).

       mls   只是將 remote 某目錄下的東東存在local 端的某檔案裡.

       mdir  相當於 mls, 但資料較豐.

       mkdir 像 UNIX 下的 mkdir 一般. (make directory)

       rmdir 像 UNIX 下的 rmdir 一般. (remove directory)

 

   (9) open, close, disconnect, user:

 

       open       開一個connection 到某個 remote ftp host.

       close      關閉目前的connection.

       disconnect 相當於 close.

       user       再輸入一次username 和 password. (有點像 UNIX 的 su)

 

備註:

 

 - 抓取整個目錄(包括子目錄)的方法:

 

   (1) 使用 X 環境下的 ftptool, mftp 一類工具.

 

   (2) 若 ftp site 支援 tar, 先打包再行傳送.

 

   (3) 利用 mirror.

 

 - 把 ftp 丟到幕後 (background) 執行:

 

   (1) 正當你在 ftp-ing 時, 按 Ctrl-Z (Enter) 和 bg (Enter) 就行囉.

 

   (2) 首先在 .netrc 檔內要有該 ftp site 的對應指示.

       再建一個 script 檔, 之後用 nohup 指令即可.

 

       e.g. 要到 140.117.11.3 抓檔, 先建一個叫 ftp.scr 的檔, 內容為:

 

       bin

       prompt

       cd ????

       mget ???????

       bye

 

       之後在 UNIX 下打 nohup ftp 140.117.11.3 < ftp.scr&

       記得 .netrc 檔中必須包含下行:

 

       machine 140.117.11.3 login ftp password <username@>

 

       注意: .netrc 檔 mode 應為 400. 若失敗, 試試 chmod 400 .netrc

              .netrc 檔應置於 $home 目錄下.

              <username@> 為你的 LoginUser ID 後加一個 @ 字號.