我正在寻找一个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我使用一些随机密码作为测试,而不是以前使用的空白(null),但仍然得到相同的错误。我怎么才能解决这个问题?
发布于 2017-04-22 15:21:17
关闭交互模式:
ftp -i -n FTP_SERVER <<EOF >outputfile
user <user> <password>
binary
ls -la .
quit
EOF发布于 2017-04-22 16:04:20
你可能会和lftp相处得更好
lftp -e 'ls -l someFile.zip; quit' -u USER,PASSWORD FTPSERVER > ls.txt所有的大写单词都需要被你自己的价值观所取代。
或者你可以尝试使用curl
curl ftp://FTPSERVER --user USER:PASSWORDhttps://stackoverflow.com/questions/43560422
复制相似问题