Justin Nafe
Justin Nafe

Reputation: 3062

linux ftp lcd error No such file or directory

I wrote a bash script to connect to an ftp server and download files from the FTP server to different directories on my local linux box.

I am using the following to achieve this.

#! /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

I had to use USSER to login because USER is a keyword

Also, I was able to manually run the commands without any error.

Does anyone know what the issue could be? Any help with this or leads on where to look would be greatly appreciated.

Edit

When I run the script, I get the following and notice how the error message covers up most of the path that it is echoing

# 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.

Upvotes: 0

Views: 3100

Answers (1)

Alan Curry
Alan Curry

Reputation: 14731

The reason the error message is overwriting itself is that your filename is included in the error message, and a carriage return is included in your filename. You need to dos2unix that thing and stop editing unix scripts with DOS-ish editors.

Upvotes: 2

Related Questions