2011-06-22 29 views
2

我正在使用遞歸搜索SAN上的目錄查找具有比4小時更新的特定文件名的文件的Bash腳本(請參見下文)。然後將所有這些文件複製到特定的FTP位置並通過電子郵件發送,以表明副本已完成。該腳本工作正常,只是它只複製頂級目錄中的文件。我在較低目錄得到的錯誤是這樣的:BASH遞歸查找文件名並複製到ftp

remote: -v 
ftp: local: -v: No such file or directory 
local: ./Test01/test02/folder02_01_1200_m30.mp4 remote: ./Test01/test02/folder02_01_1200_m30.mp4 
229 Entering Extended Passive Mode (|||45127|) 
550 ./Test01/test02/folder02_01_1200_m30.mp4: File does not exist. (2) 
221 Goodbye. 

這裏是腳本

#!/bin/bash 
#The location from where the script should search 
GSPORIGIN='/Volumes/folder01/folder02' 

#File Names to be moved 
FILE1='*1200_m30.mp4' 

#FTP Details 
HOST='xxxx.upload.com' 
USER='xxxxxxx' 
PASSWD='xxxxxxxxxxxx' 
#the destination directory on the FTP 
DESTDIR="/8619/_!/TEST" 


# Go to the location from where the search should start 
cd $GSPORIGIN 
for file in `find . -type f -name "*1200_m30.mp4" -mmin -240` 
do 
echo $file 
if [ -f $file ] ; then 
ftp -n -v $HOST << EOT 
ascii 
user $USER $PASSWD 
prompt 
cd $DESTDIR 
mput -v $file 
EOT 
echo "$file has been copied to FTP" | mail -s "$file has been copied to FTP in Directory $DESTDIR" [email protected]; 
else exit 1 
fi 
done 

回答

2

做你做什麼,你就必須重新創建目標FTP上的目錄。 使用基名/目錄名稱commmands和mkdir命令是這樣的:

for file in `find . -type f -name "*1200_m30.mp4" -mmin -240` 
do 
echo $file 
if [ -f $file ] ; then 

destdirname=`dirname "$file"` 

ftp -n -v $HOST << EOT 
ascii 
user $USER $PASSWD 
prompt 
cd $DESTDIR 
mkdir $destdirname 
mput -v $file 
EOT 
echo "$file has been copied to FTP" | mail -s "$file has been copied to FTP in Directory $DESTDIR" [email protected]; 
else exit 1 
fi 
+0

感謝您的快速回復 - 當我運行腳本時會創建目錄,但無法移動文件:./Test_1200_m30.mp4 嘗試96.7.36.11 ... 已連接到ftp.xxxxxxxxx.net 。 220內容存儲FTP服務器 530請用USER和PASS登錄 331 XXXXX所需的密碼。 230用戶stor_admin登錄。 遠程系統類型是UNIX。 使用二進制模式傳輸文件。 交互模式關閉。 250 CWD命令成功。 550。:禁止文件名(4) 250 CWD命令成功。 用法:put local-file [遠程文件] 221再見。 ./Test_1200_m30.mp4 – JRM

+0

好的只是修復了它 – JRM

+0

修復程序是mput -v $文件$ filename – JRM

2

要在嵌套目錄複製多個文件:我建議你看看rsync utility爲你做這項工作。

rsync會在需要時創建所有的遠程目錄,即使經常運行,它也會保持文件完全同步。

相關問題