天天看點

shell中使用FTP

FTP的指令行格式為:ftp -v -d -i -n -g [主機名]

其中 -v 顯示遠端伺服器的所有響應資訊; -n 限制ftp的自動登入,即不使用.n etrc檔案。

在shell中使用ftp 寫道

FTP_SERVER=10.56.235.1

FTP_USER=ftpUser

FTP_PASS=ftpPassword

FTP_DIR=/ftpUser/ftp

FTP_RESPONSE=`ftp -n -v << EOF 2>&1

open $FTP_SERVER

user $FTP_USER $FTP_PASS

cd $FTP_DIR

ls -l

bye

EOF`

echo "$FTP_RESPONSE"

注意:

command line<<EOF 

(内容) 

EOF

EOF隻是一個分界符,其實你完全可以用abcde替換,也一樣的功能,隻是大家都習慣用EOF來表示。

簡要回顧一下<<的用法。當shell看到<<的時候,它就會知道下一個詞是一個分界符。在該分界符以後的内容都被當作輸入,直到shell又看到該分界符(位于單獨的一行)。這個分界符可以是你所定義的任何字元串。

command line:比如ftp、cat等

詳細内容檢視下面的連結:

<a href="http://www.linuxsir.org/main/doc/abs/abs3.7cnhtm/here-docs.html" target="_blank">http://www.linuxsir.org/main/doc/abs/abs3.7cnhtm/here-docs.html</a>

在C/C++中,EOF: is returned by an I/O routine when the end-of-file (or in some cases, an error) is encountered.

-------------------------------------------------------------------------------------

ftp  -n -v&lt;&lt;EOF

open 192.168.0.212

user anonymous ''

cd /pub/

get extsuite.tgz

本文轉自leonardos51CTO部落格,原文連結:http://blog.51cto.com/leomars/1374138 ,如需轉載請自行聯系原作者