我编写了一个 bash 脚本来连接到 ftp 服务器并将文件从 FTP 服务器下载到本地 linux 机器上的不同目录。
我正在使用以下方法来实现这一点。
#! /bin/sh
FILENAME='helloworld.txt'
USSER='username'
PASSWD='password'
ftp -niv ftp.domain.com <<HEREDOC
quote USER $USSER
quote PASS $PASSWD
lcd /home/username/scripts/data
mget $FILENAME
bye
HEREDOC
我必须使用 USSER 登录,因为 USER 是关键字
此外,我能够手动运行命令而没有任何错误。
有谁知道问题可能是什么?对此的任何帮助或在哪里寻找的线索将不胜感激。
编辑
当我运行脚本时,我得到以下信息并注意到错误消息如何覆盖了它正在回显的大部分路径
# bash test.sh
test.sh: line 11: warning: here-document at line 5 delimited by end-of-file (wan')d `HEREDOC
Connected to ftp.domain.com (ipaddress).
220 Welcome to the domain FTP Server
331 Password required for username.
230 User username logged in.
: No such file or directoryts/data
local: helloworld.txt remote: helloworld.txt
227 Entering Passive Mode (216,19,206,212,226,85)
150 Data connection accepted from myipaddress:54375; transfer starting for /helloworld.txt (107828 bytes)
226 File sent ok.
107828 bytes received in 0.137 secs (789.81 Kbytes/sec)
?Invalid command
?Invalid command
221 Goodbye.