linux - 使用 shell 脚本将 FTP 输出重定向到我的 linux 机器上的文件

标签 linux bash shell ftp

我正在寻找一个 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/

相关文章:

linux - 默认用户 ubuntu ec2 被意外删除

java - 手机SDK的Linux二进制文件

linux - 如何在脚本中限制 bash 命令的终端输出

bash - 忽略 join 命令中的 header (过时的 coreutils)

linux - Bash 命令(netstat 等)显示数据包传输概览?

linux - 如何在linux脚本中提取字符串中的数字和特殊字符

ruby-on-rails - git status 显示将开发平台从 Windows 更改为 Linux 后修改的文件列表

linux - Bash - 在多个目录中查找并替换文件中的一行

bash脚本: Delete characters in string up to and including a phrase?

shell - 如何在 shell 脚本中使用 chmod