我有一噸左右使用以下功能的腳本:如何改進這個FTP(shell)函數?
# Copies files over using FTP.
# Configurations set at the beggining of the script
# @param $1 = FTP Host
# $2 = FTP User
# $3 = FTP User password
# $4 = Source file name
# $5 = destination directory
# $6 = local directory
doftp() {
log_message_file "INFO" "Starting FTP"
ftp_hst=$1
ftp_usr=$2
ftp_pwd=$3
sourcefile=$4
destdir=$5
locdir=$6
ftp -nv $FTPH << EOF 2> ftp.err.$$
quote USER $ftp_usr
quote PASS $ftp_pwd
cd $destdir
lcd $locdir
bin
put $sourcefile
bye
EOF
if [ "$(wc ftp.err.$$|cut -d" " -f8)" != 0 ] ; then
log_message_file "ERROR" "Problem uploading files: $(cat ftp.err.$$)"
else
log_message_file "INFO" "FTP finished"
fi
rm ftp.err.$$
}
它的工作原理,做它的工作,除非FTP失敗。幸運的是,對於我來說,腳本非常精確,FTP幾乎從不失敗。但是,當人們有機會(時間)返回並查看TODO列表中標記的代碼時,這就是其中的罕見時刻之一。唯一的問題是我不太確定如何改善它......我會帶你們在那裏改變什麼的建議。
一個明顯的問題是從ftp解析錯誤,這是一個完全跛腳的問題。但我也會考慮其他部分的功能:)
值得一提的是在AIX服務器上運行?哦,不,我不能使用SFTP :(
感謝任何投入!
PS:log_message_file僅僅是一個基本的日誌...在功能沒有影響。
也許這更適合codereview.stackexchange.com – 2011-04-05 16:30:46
你使用哪個shell?例如用ksh和bash,'$(
2011-04-05 17:39:46
謝謝!這是ksh。但它真的值得改變嗎?我的意思是,我猜「貓」會讓它更加跨平臺,對吧? – filippo 2011-04-06 08:32:24