我正在寻找一个 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
我使用了一些随 secret 码作为测试而不是我之前使用的空白(空),但仍然得到同样的错误。我该如何解决这个问题?
最佳答案
关闭交互模式:
ftp -i -n FTP_SERVER <<EOF >outputfile
user <user> <password>
binary
ls -la .
quit
EOF
关于linux - 使用 shell 脚本将 FTP 输出重定向到我的 linux 机器上的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43560422/