Unix Shell Script FTP issue

Hey guys, I’m hoping someone can help me out here. I wrote a shell script to automate uploading a file to another server via FTP.

I’ve tested doing this via ftp from the prompt and it works file. I’ve written the same thing in a shell script yet it doesn’t work. The script is below:

#!/bin/sh
ftp -v -n host << EOF
user xxxxx password
cd /remotedirectory/xxxx/
lcd /localdirectory/xxxx/
put mySQLResults.txt
bye
EOF

When I run this script from the command line, it returns:

Connected to edxxxx.xxx.xxx.com (142.17x.xxx.xxx).
220 FTP server ready.
Remote system type is UNIX.
Using binary mode to transfer files.
331 Password required for xxxxx.
230 User xxxxx logged in.
250 CWD command successful.
: No such file or directory
remote: mySQLResults.txt
: No such file or directory
?Invalid command
?Invalid command
221 Goodbye.

If I manually type the commands at the shell, it works fine, but when I run the script, it doesn’t. Can anyone help me out with this one please?

Thanks

I believe the first comment in the following thread should help you

Well thanks for the reply, but that wasn’t helpful at all.

I managed to resolve this, and the solution wasn’t because of my code being incorrect, but rather because of where I wrote it. I wrote it in notepad, in windows, and then uploaded this to unix.

The issue is that the heredoc interpretes newlines differently than windows does, so to resolve this, I just redid this in a new file using VI from the ssh prompt. Changed nothing, and viola!! it worked.

So incase anyone ever have any problems with shell scripting, make sure you don’t write your code in a windows editor and try to execute in Unix shell :slight_smile: