Operating System - HP-UX
1829778 Members
1714 Online
109992 Solutions
New Discussion

FTP script on HP-UX won't send password to Windows FTP server

 
SOLVED
Go to solution
Matt Hearn
Regular Advisor

FTP script on HP-UX won't send password to Windows FTP server

Hey all! My customer has a script they've been using to move some data files over FTP to a Windows server. Recently the Windows guys decommissioned the old box and put a new one in; I'm not sure what the difference is, but now their scripts aren't working.

I realize this method is unbelievably unsecure, but the customer is loathe to make changes to what was once a functional procedure.

The script is basically doing this:

-------------------------------
RC=`/usr/bin/ftp -nv <open new.server.com
user ftpuser password
put datafile.1
put datafile.2
bye
EOF_FTP`
print "Return code was: " ${RC}
-------------------------------

However, when I run it, it's now prompting me for the password. I'm not in the mood to completely recode their scripts into "expect", not least because I can never get that to work properly either. :)

Can anyone thing of a way in which you can pass the password to the server and not have it prompt? I've tried a bunch of stuff, including:
-------------------------------
user ftpuser
password
-------------------------------

and:
-------------------------------
user ftpuser\npassword
-------------------------------

I'm pretty stumped. Is there something that the Windows goons need to change on their FTP server settings?

I do know if I do an ftp -nv from the command line, do an "open server.etc", and then type "user ftpuser password", it logs me right in. It just seems to get angered by the space between "user ftpuser" and "password" in the script and treats it like a newline, and then breaks out of the script to prompt me for a password. Argh!

Thanks!
5 REPLIES 5
Court Campbell
Honored Contributor

Re: FTP script on HP-UX won't send password to Windows FTP server

Have you ever thought that maybe that user account does not exist on the windows ftp server. Maybe they did not set up the new machine exactly as the old one. I would start with asking the windows admins questions about is the account exists first.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Patrick Wallek
Honored Contributor
Solution

Re: FTP script on HP-UX won't send password to Windows FTP server

I am doing essentially the same thing.

I've got a script that does:

ftp -n -v << EOFL >> LOG
open 1.2.3.4
user name pass

bye
EOFL

It works as it should.

I have to wonder if it is getting confused because of the way you have the FTP Script being executed to assign the result to a variable.

What happens you you just do the FTP, then afterwards, do RC=${?} so your script looks like:

/usr/bin/ftp -nv <open new.server.com
user ftpuser password
put datafile.1
put datafile.2
bye
EOF_FTP
RC=${?}
print "Return code was: " ${RC}

By the way, your RC here will ALWAYS be 0. You are exiting FTP with the bye command and that will always have a return code of 0. Even if the ftp fails to login, or fails to transmit a file, your RC will always be 0.
Matt Hearn
Regular Advisor

Re: FTP script on HP-UX won't send password to Windows FTP server

You're right, I removed the backticks from the file and it works now. Thanks!
A. Clay Stephenson
Acclaimed Contributor

Re: FTP script on HP-UX won't send password to Windows FTP server

Who knows with Windows and their FTP implementation. In any event, I would beat you over the head for this Mickey Mouse stuff because you don't bother to check the validity of the transfer. You don't have a clue if it worked or not. There is a much easier way to do this -- and it will implicitly handle the password handshaking for you --- and will provide meaningful status. Use Perl's Net::FTP module. The attached Perl script, ftpput.pl, will do everything for you and you don't need to know any Perl.

Your transfer will be very close to this:

ftpput.pl -h new.server.com -l ftpuser -p password -A datafile.1 datafile.2
STAT=${?}
if [ ${STAT} -ne 0 ]]
then
echo "FTP failed; status ${STAT}." >&2
fi
exit ${STAT}

You can even put your passwd in a .netrc file to make it a bit more secure.

Invoke as ftpput.pl -u for full usage. The really neat thing about this approach is that the Perl script will work equally well if run on Windows -- if one of the free Perls for Windows is installed.
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: FTP script on HP-UX won't send password to Windows FTP server

Shalom,

Who ever said that Windows had to follow standards? Their ftp server breaks rules and dos not follow standards at all.

You will need to modify the script to make it work and know that the script won't work with a REAL ftp server.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com