Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automatic ftp from local pc to unix server

Status
Not open for further replies.

charmingcann

Programmer
Jul 17, 2001
13
SG
I need to automate the transferring of file from local pc to unix server.
I've created a batch file and run this in my pc, it works. I've created a shell
script and run this in unix server, it fails.
The requirement is to create a script to automatically get the file in a local
PC and then store this in the unix server. This file will then be used in the
sql loader . Can this be done?
 
I don't understand. Are you saying you took the script that works on windows and tried to run it on Unix and are surprised that it fails??

I don't know if this will help:


From How can I automate an ftp transfer?

There are actually numerous ways to do that. If your script is complex, I'd use Kermit.

* *
You can also use "here" files:

HOST=xxx
FTPUSER=xxx
FTPPASSWORD=xxx
ftp -n $HOST <<-EOF
user $FTPUSER $FTPPASSWORD
cd /wherever
bin
prompt off
mget '*'
bye
EOF


Finally, ftp already has a scripting language built in to it. &quot;ncftp&quot; (available from Skunkware) has even more capability, but here's a basic .netrc (see man netrc) for normal ftp.

----$HOME/.netrc 600 perms --
machine somewhere.com login mylogin password mypass macdef
init
lcd /appl/fp/merge
cd /appx/data/50/XFR/Data
put artrx.tab TRXFER.dat
quit

machine someothermachine.org login whatever password pass macdef
init
hash
bin
prompt off

machine yetanother ...


The first example (somewhere.com) logs in, changes to a local directory /appl/fp/merge, then changes to /appx/data/50/XFR/Data on the server and &quot;puts&quot; a file.

With this in place, the command &quot;ftp somewhere.com&quot; will do the &quot;put&quot;. You could set &quot;prompt off&quot; and use &quot;mput&quot; or &quot;mget&quot; in the .netrc also.

The second just logs you in to &quot;someothermachine.org&quot; , turns on hash, etc. and then you can type your own commands.

You can fully script more complex things with:

#!/bin/ksh
echo &quot;machine somewhere.com login mylogin password mypass
macdef init&quot; > $HOME/.netrc
echo &quot;lcd /appl/fp/merge&quot; >> $HOME/.netrc
echo &quot;cd /appx/data/50/XFR/Data&quot; >> $HOME/.netrc
for i in *.tab
do
echo &quot;put $i ${i%tab}.dat&quot; >> $HOME/.netrc
done
echo &quot;quit&quot; >> $HOME/.netrc
echo &quot; &quot; >> $HOME/.netrc
# always end a macdef with a blank line
chmod 600 $HOME/.netrc
ftp somewhere.com


Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
If the UNIX ftp is failing is it because you don't have an ftp port open (fpt service running) on the Windows machine ?

Bill.
 
Can you manually FTP from Unix to your pc?
If you can't do it manually, a script won't work.
In order to FTP your pc, you will need
to run an ftp server running on the pc.

If you, can I would use one of pcunix's examples
above.

Sounds like you can already FTP from your pc
to Unix, but you may have to purchase
a scheduling tool to kick of your batch file.

or

Unix, has cron standard which will allow you
to schedule the ftp job to be run.

Robert G. Jordan

Robert@JORDAN2000.com
Unix Admin, United Airlines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top