linux ftp lcd错误没有这样的文件或目录

linux ftp lcd错误没有这样的文件或目录,linux,ftp,Linux,Ftp,我编写了一个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 m

我编写了一个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

错误消息覆盖自身的原因是错误消息中包含文件名,并且文件名中包含回车符。您需要
dos2unix
这样做,并停止使用DOS-ish编辑器编辑unix脚本。

运行此脚本的系统上是否确实存在
/home/username/scripts/data
?我刚刚复制了你的脚本(显然,使用了不同的文件名、用户、密码、站点等),效果很好……@twalberg Yes。我可以连接、更改本地目录和手动下载而不会出现错误,但运行脚本文件时会出现错误。请注意,错误在路径上重叠/写入。@twalberg这可能是我的系统的设置方式吗?Fedora发行版14(Laughlin)Linux 2.6.35.4-rscloud x86_64
# 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.