[英]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.