ftp in a shell script

Issues related to configuring your network
Post Reply
jason_nixon_205
Posts: 23
Joined: 2007/05/12 13:52:02
Contact:

ftp in a shell script

Post by jason_nixon_205 » 2007/05/12 14:08:04

I recently downloaded and installed centos 4.4 and it looks pretty nice so far. I guess you could say I'm some what of a linux noob. Anyway, here is my question (and any help would be greatly appreciated!):

I'm trying to get a shell script to ftp a certain file. I'm using the below syntax in the script:

#!/bin/sh
HOST='www.my_website_address.com'
USER='username'
PASSWD='password'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0


The trouble is the script doesn't work. If I try to run the script with ./ I immediately get the error:
: bad interpreter : no such file or directory

If I try to run the script with sh it attempts to run but kicks back more errors:
: command not found
: numeric argument required

According to what I've read this should be mostly simple, but it is frustrating...so, again, any help would be great!

Thanks!!

JohnC
Posts: 17
Joined: 2007/04/01 08:32:12

Re: ftp in a shell script

Post by JohnC » 2007/05/12 16:11:12

It runs ok on my CentOS5 system.
Maybe the file has spurious line breaks (or some other characters?).
If the file has windows style linebreaks instead of unix it could cause it.
Did you set it up with a standard editor?

jason_nixon_205
Posts: 23
Joined: 2007/05/12 13:52:02
Contact:

Re: ftp in a shell script

Post by jason_nixon_205 » 2007/05/12 20:45:11

That's it! It was the windows line breaks. I imported it from notepad. Also, I had to add the -u option to the ftp command so the authentication wouldn't fail. Thanks so much!!

K_Frye
Posts: 425
Joined: 2005/07/13 01:48:35
Location: Canada

ftp in a shell script

Post by K_Frye » 2007/05/14 06:27:56

[quote]
jason_nixon_205 wrote:
I recently downloaded and installed centos 4.4 and it looks pretty nice so far. I guess you could say I'm some what of a linux noob. Anyway, here is my question (and any help would be greatly appreciated!):

I'm trying to get a shell script to ftp a certain file. I'm using the below syntax in the script:

#!/bin/sh
HOST='www.my_website_address.com'
USER='username'
PASSWD='password'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

[/quote]

Just a thought but you should really try to avoid using ftp. If possible, consider setting up keys and using scp or sftp. Not only is it more secure but it will make the scripting easier since you won't need to worry about passwords.

michaelnel
Posts: 1478
Joined: 2006/05/29 16:50:11
Location: San Francisco, CA

Re: ftp in a shell script

Post by michaelnel » 2007/05/16 21:01:19

I agree about using scp instead of ftp if at all possible. Sometimes though, you don't have control over the other end of the transaction, and in those cases I would rather us "ncftpput" and "nsftpget" from the ncpftp suite of ftp tools. It is optimized for use in scripts and is much easier to use.

http://www.ncftp.com/

Good stuff.

Post Reply

Return to “CentOS 4 - Networking Support”