我写了一个 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.
最佳答案
错误消息覆盖自身的原因是您的文件名包含在错误消息中,并且回车包含在您的文件名中。您需要 dos2unix
那个东西并停止使用类似 DOS 的编辑器编辑 unix 脚本。
关于linux ftp lcd错误没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11995064/