[英]FTP output redirect to a file on my linux box using shell script
我正在尋找一個Bash腳本,以將簡單的ls
命令輸出重定向到我的FTP服務器上的Linux機器上的文件。
以下是分步命令,以說明我要編寫的腳本。 無需用戶/密碼即可訪問FTP站點,因此在出現提示時,我以anonymous
用戶身份輸入用戶名,密碼為空白。
ftp <FTP_SERVER>
Connected to <FTP_SERVER> (IP_ADDRESS).
220 Microsoft FTP Service
Name (<FTP_SERVER>:root): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230 Anonymous user logged in.
Remote system type is Windows_NT.
ftp> ls /Outgoing/Artemis/incremental/Hashes-1492870261.zip
227 Entering Passive Mode (10,37,108,77,5,87).
125 Data connection already open; Transfer starting.
04-22-17 07:11AM 227634 Hashes-1492870261.zip
226 Transfer complete.
我需要我正在執行的命令'ls'的輸出,以保存在Linux機器上的文件中。
這是我的腳本:
ftp FTP_SERVER <<EOF >outputfile
quote USER anonymous
quote PASS
prompt noprompt
ls -la /Outgoing/Artemis/incremental/Hashes-1492870261.zip
quit
EOF
當我執行此操作時,出現登錄失敗錯誤。
sh -x test.sh
+ ftp FTP_SERVER`
Password:
Login failed.
local: /Outgoing/Artemis/incremental/Hashes-1492870261.zip: No such file or directory
我使用了一些隨機密碼作為測試,而不是之前使用的空白(空),但仍然遇到相同的錯誤。 我怎樣才能解決這個問題?
關閉互動模式:
ftp -i -n FTP_SERVER <<EOF >outputfile
user <user> <password>
binary
ls -la .
quit
EOF
使用lftp
可能會更好:
lftp -e 'ls -l someFile.zip; quit' -u USER,PASSWORD FTPSERVER > ls.txt
大寫字母中的所有單詞都需要替換為您自己的值。
或者您可以嘗試使用curl
:
curl ftp://FTPSERVER --user USER:PASSWORD
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.