FTP within a SHELL script

I am running the following on linux (on a mac):

filename="/Users/thisfilename.txt"
hostname="ftp.mysite.com"
username="myusername"
password="mypassword"
echo '=======FTP========'
ftp -un $hostname <<EOF
quote USER $username
quote PASS $password

binary
put $filename
quit
EOF

I get the following error:

ftp: Invalid URL `n'

If I remove the -n flag, I get the following:

usage: ftp [-46AadefginpRtvV] [-N netrc] [-o outfile] [-P port] [-q quittime]
           [-r retry] [-s srcaddr] [-T dir,max[,inc]]
           [[user@]host [port]] [host:path[/]] [file:///file]
           [ftp://[user[:pass]@]host[:port]/path[/]]
           [http://[user[:pass]@]host[:port]/path] [...]
       ftp -u URL file [...]

anyone have any ideas???

Thanks in advance!!

Roseann

linux (on a mac)

Uhuh?

What Operating System are you issuing the ftp command on?
What Operating System are you connecting to (if known)?
What (in words not code) are you trying to do?

Brainspark!
Is the remote computer addressed by a URL (like a website) or a computer with a normal unix hostname? If it's not a URL, you do not want the "-u" switch to FTP because it is expecting a URL (eg: ftp://remotehost.com) not a computer hostname. In your case it is taking the character "n" after the "-u" as the URL !

There are probably other issues in the script with using "quote" for no apparent reason but you might be connecting to a non-unix system.

Footnote: Can you do the file transfer successfully from the command prompt? If you can, please post the sequence you type and it can no doubt be scripted.

Don't use ftp in scripts; it is intended for interactive use, and is not well suited to scripts.

Either use scp, if possible, or use the ncftp family of commands (e.g. ncftpput).

@cfajohnson
We have several thousand ftp scripts executing per day in a mixed unix environment. The scripting to achieve consistent reliability is not at all easy but it can be done without replacing each remote system.

Thanks, scp worked!

Roseann
www.GlobalNerds.com