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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sh script for FTP on AIX 5.3 1

Status
Not open for further replies.

bidon15

MIS
Sep 20, 2003
107
US
Hello, i am very newbie inn unix environment. My company just installed couple unix boxes. We have an application that needs a file from the vendor, once it's FTPed it. I am looking a way to download that file from MS windows FTP server to unix server and schedule it in the cron job. When the download completed it will remove the file from the FTP server.

Any helps is very much appreciated.

Regards,
 
If you have FTP running on the UNIX box, you could log in from the Windows box and FTP put, then delete locally. Windows does have a scheduler.

Use what you know, now, then read up on UNIX shell scripting later.



BocaBurger
<===========================||////////////////|0
The pen is mightier than the sword, but the sword hurts more!
 
Hi BocaBuger,
No, The FTP server is a windows 2003. A shell script that would do a trick for me that i need to schedule in the cron job. Thanks!
Regards,
 
Something like this maybe:

ftp -n <ip address> << EOF
user <username> <password>
ascii
cd <to where youy want to push pull data>
lcd <to where you want to push or pull data to/from>
get <filename> (to get data from the windows server)
put <filename> (to put the data from the UNIX server to Win)
bye

 
Most UNIX boxes have an FTP daemon available or running.

Try typing FTP unixhostname

from a Windows cmmand line, to see if you get a response.

If you have a cron job running, what happens if it runs and the file is not available? or even worse, it is in the process of being downloaded to the Windows box? (file locked).



BocaBurger
<===========================||////////////////|0
The pen is mightier than the sword, but the sword hurts more!
 
You could create an "expect" script (expect is available from bullfreeware.com or ucla.edu or ibm.com) and then execute it with positional parameters such as:

scriptname servername username password filename

and it will connect, login, retrieve the file then delete it.

Give it a whirl. If you need to change to a specific directory you should be able to figure that out. Also, see "man expect" and man "ftp".

Good luck.

Bob


#!/usr/bin/expect
################################################ # Script to retrieve file via ftp and remove
#
# Usage: scriptname servername username password filename
#
# Parse Positional Parameters from command line set argc [llength $argv]; for {set i 0} {$i<$argc} {incr i} { set P($i) [lindex $argv $i] } ################################################ # Start the sftp communications session set timeout -1 spawn ftp -i "$P(1)@$P(0)" expect " password:" send "$P(2)\r" expect "ftp>" send "get $P(3)\r" expect "ftp>" send "del $P(3)\r" expect "ftp>" send "bye\r" ################################################ # Quit the expect session and exit exit

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top