Operating System - HP-UX
1829617 Members
2203 Online
109992 Solutions
New Discussion

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

 
ajk_5
Frequent Advisor

Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Dear all,

Could you tell me how to write a unix script which upload .txt files from remote sites (PC workstation) to a directory at rp5470 server?
Thanks very much!



Best Regards
Ajk
28 REPLIES 28
Hoefnix
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

What OS are these PC's running and what software do they use to upload these .txt files manual?
Whitout this info, it is not easy to write a script that will work for you.

Regards,
Peter
Steven E. Protter
Exalted Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

http://hpux.connect.org.uk/hppd/hpux/Networking/FTP/snarf-7.0/

snarf is good for downloads. I Think it can be used for scripted uploads as well.

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
Steven E. Protter
Exalted Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

If its NT/W2K/XP Pro it probably has an ftp server that you can set up. That would let you use snarf to pull the files off the PC or use a standard ftp script to put files on the HP box.


#######################
#Start Ftp and get file#
########################
ftp -nv ${SERVER} << FTPEOF > /tmp/temp_log.$$
user ${USERNAME} ${PASSWORD}
#Get file
get $1
quit
FTPEOF

put works just fine too.

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
Karthik S S
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Try this,
for IP in 'list_of_IPs_separated_by_space'
do
ftp -n -v >> 'ftp.log' 2>> 'ftp.log' <open $IP
user username password
cd remote_directory
prompt
mget *.txt
quit
EOF
done

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Dear all,

Those PC workstations will be W2K. Can I not use userid and password in the script to upload files to the unix server? Also, I use DHCP assign IP to the PC workstations. Is it possible to use the PCs' Host Name instead in the script? How can I do that? Thank you!



Best Regards
Ajk
Karthik S S
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Change the script as,

Try this,
for HOST in 'list_of_hostnames_separated_by_space'
do
ftp -n -v >> 'ftp.log' 2>> 'ftp.log' <open $HOST
user username password
cd remote_directory
prompt
mget *.txt
quit
EOF
done



Why do you need to use User ID / password? Instead use the username and password. Is the username is same across all the NT hosts?? If it is different then you will have problem with this script.

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Jan Zalman
Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Hi, see the http://lexa.mckenna.edu/sshwindows/
sshd server for Wins. Its possible
to start the connection from unix without the passwd, to do so you have to generate & deploy the sshkey pairs. I experienced with on W2K and WXP sucesfully (hint: UsePrivilegeSeparation no). However, from some reason I don't know the passwordless login (key based autentification) didn't work on Win2003 server. According to docs it should work, but I didn't figure out the solution even after hours of googling. But W2K and XP no problem. Best regards.
Time and loyalty cannot be bought.
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Hi Karthik S S,

I am kind of confusing... From your script, the username and password is "root" in unix users? So I don't need to care the username and password at the PC workstation?? Would you explain it, please? Thank you very much.



Best Regards
Ajk
Karthik S S
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Hi AJK,

Well let me put it this way,

What you need is to download some *.txt file from remote Windows PCs running ftp to a directory in your rp5470 server right?. So first login to the RP5470 server using some user name / password (root user in your case. May be you can create a directory using,

mkdir /textfiles

cd /textfiles

vi myscript
(copy and paste the script that I have posted. Change the following line,

user username password

to

user username_of_the_windows_PC password_of the_windows_PC

and finally save the file )

chmod +x myscript

./myscript


I hope the things are clear now ...

-Karthik S S

(Here I assume that the username/password are same for all the windows PCs).
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Geoff Wild
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Another way to accomplish this is with Samba:

http://software.hp.com/portal/swdepot/displayProductInfo.do?productNumber=B8725AA

Create a share on your HP-UX box, and map a drive from your W2K clients to it. Then from the W2K boxes, save the .txt files to that share. You could even create a simple bat job on the W2K boxes to copy or move the files if you like - better to just place them in the share from the start...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Karthik S S,

I did follow your steps creating the script, but it was not working. When I look at the ftp.log, it shows:

ftp: cpu1212: Unknown host
Not connected.
Not connected.
Interactive mode off.


Did I do something wrong? Thanks.



Best Regards
Ajk
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Here is the script I write:



for HOST in 'cpu1212'
do
ftp -n -v >> 'ftp.log' 2>> 'ftp.log' <open $HOST
user isajk xxx
cd \test
prompt
mget *.txt
quit
EOF
done



Best Regards
Ajk
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Dear all,

Could you help me to solve the problem, please? Thanks a lot!



Best Regards
Ajk
Hoefnix
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Is the cpu1212 the file that contains the hosts that you like to connect to with FTP?

Then it should be like this:
for HOST in 'cat /path-to-file/cpu1212'
do
ftp -n -v >> 'ftp.log' 2>> 'ftp.log' <open $HOST
user isajk xxx
cd \test
prompt
mget *.txt
quit
EOF
done

The hosts in the file, must be resolvebale by the system. (check before starting the script with ping or nslookup)

Regards,
Peter
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Hi!

My script is shown as the following:

for HOST in 'cat /home/hostfile'
do
ftp -n -v >> 'ftp.log' 2>> 'ftp.log' <open $HOST
user isajk xxxxxx
cd \test
prompt
mget *.txt
quit
EOF
done


And the hostfile contains the host name 'cpu1212' only.

When I run the script, nothing happens and I see the ftp.log:

cat: bad port number-- /home/hostfile
usage: open host-name [port]
Not connected.
Not connected.
Interactive mode off.
Not connected.


What should I do?? Any help?
Hoefnix
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

user the quotes ` in stead of '
for HOST in `at /home/hostfile`

Then it should work.
Regards,
Peter

Sorry that I missed this one in the previous post.

Hoefnix
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

a typo :
for HOST in `cat /home/hostfile`
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Hi,

I just feel frustrated as the ftp.log is shown:


ftp: connect: Connection refused
Not connected.
Not connected.
Interactive mode off.
Not connected.


Did I do something wrong??
Hoefnix
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

are you able to logon manually? Using the same hostname, username and password?

This should result in the same error.
Is the FTP deamon running on the remote host where FTP is trying to connect?

Regards,
Peter
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Hi,

I did type the username and password for PC workstation in the script correctly. Actually, the server is at the remote site now, not in my office. Also, the PC workstation will be at ANOTHER remote site. What should I do in this case? Thanks very much.



Best Regards
Ajk
Hoefnix
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

What I meant was, are you able to logon with FTP without using the script. Not to test the username/password , but to see if the FTP server at the remote site (to wich you try to connect to) is running.
Because you get a connection refused, it most of the times when there is no FTP server running.

First test it manual, if thats working your script will be able to do the same trick for you.

Regards,
Peter
T G Manikandan
Honored Contributor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

ftp connection refused tells like any restrictions for the client connections given on the server.

check whether you can do a ftp from the command line without using the script.

Also do attach the contents of hostfile
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Here is the attached file 1.
ajk_5
Frequent Advisor

Re: Look for a script upload .txt files from remote sites (PC) to a rp5470 server

Here is the attached file 2.