help with a unix script to transfer files from windows to hp-ux (260 Views)
Reply
Super Advisor
NDO
Posts: 536
Registered: ‎12-10-2003
Message 1 of 7 (260 Views)

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

Honored Contributor
Steven Schweda
Posts: 9,091
Registered: ‎02-23-2005
Message 2 of 7 (245 Views)

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

Super Advisor
NDO
Posts: 536
Registered: ‎12-10-2003
Message 3 of 7 (240 Views)

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
Steven Schweda
Posts: 9,091
Registered: ‎02-23-2005
Message 4 of 7 (235 Views)

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

Acclaimed Contributor
Dennis Handly
Posts: 25,207
Registered: ‎03-06-2006
Message 5 of 7 (230 Views)

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
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 6 of 7 (200 Views)

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
Acclaimed Contributor
Dennis Handly
Posts: 25,207
Registered: ‎03-06-2006
Message 7 of 7 (195 Views)

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"

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.