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

ftp script question 1

Status
Not open for further replies.

Bealy

IS-IT--Management
Apr 20, 2002
68
AU
I need to copy a file each day (by FTP) to our Web server in the DMZ. I can manually use FTP from the command line, but I want to create a batch file and run it as a scheduled task. The FTP server needs authentication so a username and password is necessary.

I tried using a line like this.

ftp (IP Address)user: (username) pwd: (Password) put c:\x.txt w.txt y

Am I right off the track or is that close?
 
You could use TFTP (Trivial FTP) from a command line prompt BUT you don't need to use a username or password (scarey stuff). You would have to lockdown your firewall to stop TFTP coming in from the Internet.

To use TFTP the batch file line would look something like...

TFTP <ip address> PUT C:\x.txt w.txt New Zealand, a great place to visit.
 
I've worked with WS-FTP Pro in the past, and it has a scheduler with automation in it. It takes a little bit to program, but once you get going, it is really smooth.
 
I know you can do this with one hitch: you'll have to record the username and password in the script. I've done this with much success, but you'll have to make sure the script is secure - not much use locking the door if you leave the key in the lock. Anyway, you use 2 files, a batch file and an ftp script (things you'll need to replace typed in CAPS; only the first two lines of SCRIPT.FTP are important to your question, the remainder is pure example):

<FILE.BAT>
ftp -n HOSTNAME.YOUR.NET < SCRIPT.FTP

<SCRIPT.FTP>
user MYUSERNAME
password MYPASSWORD
DELETE OLDSTUFF
GET FILETOGET
PUT FILETOPUT
 
I had a similar need (pushing a SQL Server derived file to an HP-UX box for Oracle use) and couldn't get the syntax to work. A co-worker managed to stumble across the proper syntax for our environment (Win2K). Here's what we did:

<FILE.BAT>
ftp -v -n -s:SCRIPT.FTP HOSTNAME.YOUR.NET

<SCRIPT.FTP>
user MYUSERNAME
MYPASSWORD
PUT FILETOPUT DIRECTORY/FILENAME

Following the previous format, replace uppercase text with your own information.
 
No luck.
I tried both djeremyperkins and pradams930s' suggestions with no success.

If I have no file association for *.FTP so I can't see how it can interact with the batch file.

Any ideas?
 
>>If I have no file association for *.FTP so I can't see
>>how it can interact with the batch file.

Your output file name isn't known? Is there a reason you can't give it the same name each time? If not, why not generate the *.FTP file dynamically within the script that generates the output itself (that way you know the name of the file to push)?

Given your original question (ftp (IP Address)user: (username) pwd: (Password) put c:\x.txt w.txt y), here's an example:

set DIRNAM=joedir\datadirset FNAME=x.txt
set DESTFNAME=w.txt
echo 'user joe' > script.ftp
echo 'joepassword' >> script.ftp
echo 'put %FNAME% %DIRNAM%%DESTFNAME%' >> script.ftp


Other ways to do it include parameters being passed into a script. Would any of that work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top