2012-08-16 155 views
0

我寫了一個bash腳本來連接到ftp服務器,並將文件從FTP服務器下載到我本地Linux機器上的不同目錄中。linux ftp lcd error沒有這樣的文件或目錄

我正在使用以下來實現此目的。

#! /bin/sh 
FILENAME='helloworld.txt' 
USSER='username' 
PASSWD='password' 
ftp -niv ftp.domain.com <<HEREDOC 
quote USER $USSER 
quote PASS $PASSWD 
lcd /home/username/scripts/data 
mget $FILENAME 
bye 
HEREDOC 

我不得不用USSER登陸,因爲用戶是關鍵字

而且,我可以手動運行該命令沒有任何錯誤。

有誰知道這個問題可能是什麼?任何與此有關的幫助,或導致在哪裏看,將不勝感激。

編輯

當我運行該腳本,我得到以下並注意該錯誤信息是如何覆蓋了大部分的路徑,這是呼應

# bash test.sh 
test.sh: line 11: warning: here-document at line 5 delimited by end-of-file (wan')d `HEREDOC 
Connected to ftp.domain.com (ipaddress). 
220 Welcome to the domain FTP Server 
331 Password required for username. 
230 User username logged in. 
: No such file or directoryts/data 
local: helloworld.txt remote: helloworld.txt 
227 Entering Passive Mode (216,19,206,212,226,85) 
150 Data connection accepted from myipaddress:54375; transfer starting for /helloworld.txt (107828 bytes) 
226 File sent ok. 
107828 bytes received in 0.137 secs (789.81 Kbytes/sec) 
?Invalid command 
?Invalid command 
221 Goodbye. 
+0

執行此腳本的系統上是否存在「/ home/username/scripts/data」?我只是複製你的腳本(顯然不同的文件名,用戶名,密碼,網站等),並且它工作的很好.... – twalberg 2012-08-16 21:28:32

+0

@twalberg是的。我可以連接,更改本地目錄並手動下載而不會出錯,但運行腳本文件時出現錯誤。請注意,錯誤在路徑上重疊/寫入。 – 2012-08-16 21:57:18

+0

@twalberg難道這是我的系統安裝的方式嗎? Fedora 14(Laughlin) Linux 2.6.35.4-rscloud x86_64 – 2012-08-16 22:02:01

回答

2

原因的錯誤消息覆蓋本身就是您的文件名被包含在錯誤信息中,並且您的文件名中包含回車符。你需要dos2unix那件事,並停止用DOS-ISH編輯器編輯unix腳本。

+0

謝謝,我在vim中重寫了它,它工作正常! – 2012-08-16 22:13:42

相關問題