Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

help with a unix script to transfer files from windows to hp-ux

Super Advisor

help with a unix script to transfer files from windows to hp-ux

I have the following script to transfer a file, but ist not doing what he supposed to do it:

 

#! /usr/bin/ksh

HOST=my_windows_system
USER=ftp_ndo
PASSWD=123abcD

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd Ordens
print -p binary
print -p get Shipment.csv
print -p bye

wait
exit 0

 And when I run it, I have the following output:

 

 ./get_dealer_voucher.ksh
Connected to my_windows_system
220-FileZilla Server version 0.9.39 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
331 Password required for ftp_hm
530 Login or password incorrect!
Login failed.
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
221 Goodbye

 So I am not getting the file

6 REPLIES
Honored Contributor Honored Contributor

Re: help with a unix script to transfer files from windows to hp-ux

 
Super Advisor

Re: help with a unix script to transfer files from windows to hp-ux

I have corrected my mistake, but still:

 $ vi get_dealer_voucher.ksh
"get_dealer_voucher.ksh" 18 lines, 230 characters
#! /usr/bin/ksh

HOST=10.100.48.41
USER=ftp_hm
PASSWD=P@$$w0rd

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd Ordens
print -p binary
print -p get Shipment.csv
print -p bye

wait
exit 0

 and the result:

 

 ./get_dealer_voucher.ksh
Connected to 10.100.48.41.
220-FileZilla Server version 0.9.39 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
331 Password required for ftp_hm
530 Login or password incorrect!
Login failed.
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
530 Please log in with USER and PASS first.
221 Goodbye

 

Honored Contributor Honored Contributor

Re: help with a unix script to transfer files from windows to hp-ux

 
Acclaimed Contributor Acclaimed Contributor

Re: help with a unix script to transfer files from windows to HP-UX

>exec 4>&1

 

Why are you using something so complex?  Just use a simple here doc:

ftp -nv $HOST <<EOF
user $USER $PASSWD
cd Ordens
binary
get Shipment.csv
bye
EOF

 

You still may have to pay attention to Steven's statement about quoting.

Honored Contributor Honored Contributor

Re: help with a unix script to transfer files from windows to HP-UX

Regarding quoting, you should know that "$$" means "insert the PID of the current shell session here".

So, if your script is running with PID 16404 when it gets to this line:

PASSWD=P@$$w0rd

 it replaces "$$" with "16404", and your script will end up sending the password as "P@16404w0rd".

 

The solution is to put single quotes around the password string:

PASSWD='P@$$w0rd'

 Double quotes won't work here: within double quotes, the shell will still attempt to replace variable names (=anything beginning with the $ character) with their respective values. Within single quotes, this won't happen.

 

The only character that has a special meaning within a single-quoted string is the single-quote character itself.

If your password actually includes a single-quote character, it can be represented by closing the single-quote, typing \' (backslash and single-quote), then opening another single-quoted string.

Example:

$ echo 'R3@lly\H@rd'\''P@$$w0rd'
R3@lly\H@rd'P@$$w0rd

 

 

MK
Highlighted
Acclaimed Contributor Acclaimed Contributor

Re: help with a unix script to transfer files from windows to HP-UX

>The only character that has a special meaning within a single-quoted string is the single-quote.

 

Not really "within" but "end" of the string.

>closing the single-quote, typing \' (backslash and single-quote)

 

Rather than stuttering quoting it's probably easier to use "\" within ("):

echo "R3@lly\\H@rd'P@\$\$w0rd"