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

Status
Not open for further replies.

mayh3m

Technical User
Jul 12, 2002
84
ZA
Hi Everyone

Not very good with scripts, so your help and patience will be much appreciated.

I need a script that will ftp files from my windows 2003 server to a FTP server once a week. Obviously, it needs to authenticate at the same time. I don't find any option if I search in the help file for FTP. Is this possible?

Thanks
Brendon
 
Sorry one more thing - is it possible to increment the name of the remote file on a weekly basis. It musn't overwrite the remote file and the files need to stay there for 3 years?
 
for the scripting i can help you, but as far as incrementing i don't know what to tell you, (I'm not too good either..)
make a bat file like the following

ftp -s:somefile.txt 192.168.x.x
exit
The "-s:somefile.txt" file tells it to look to the file somefile.txt for the rest of the commands.

your somefile.txt will look something like this:

username
password
send
file_you_want_to_upload_here (repeat as necessary)
close
bye

I use a script similar to this to update ssi's on a company website.
I'm pretty sure that you can use the mput command instead of the send command to send multiple files, just that I haven't figured the syntax to confirm the upload.

hope this helps,


 
Here's one possible batch file:
***
@echo off

rem Set variable to create the filename
for /f "tokens=1-4 delims=/ " %%i in ('date /t') do set dtfile=%%l-%%j-%%k

rem Change to the directory where the file resides
cd \location\of\file

rem Copy the file to a different file to add today's date to the name
rem Could rename instead of copy if you wanted
copy file.ext file-%dtfile%.ext

rem Create the FTP script. This will overwrite any existing script
echo open ftpserver>script.ftp
echo USER username>>script.ftp
echo password>>script.ftp
echo send file-%dtfile%.ext>>script.ftp
echo close>>script.ftp
echo quit>>script.ftp

rem Now run FTP and specify the script we just created
rem Turn on verbose logging and turn off interactive prompting
ftp -v -i -s:script.ftp
***
Notes: I've seen some different formats for sending the username, so you may have to play with that part. You can search this forum and probably the Windows 2000 forum and scripting forums for "ftp script".

I also haven't tested this, so use at your own risk :)

Hope this helps.
 
Hi Crobin

Thanks. This works perfectly thank you!
Just one thing more if you don't mind?
How do I add the year to the date? I need to keep these for 3 years, so the year has to be on there.

Thanks again for the help

Regards
Brendon
 
You'll need to play with the following line:
for /f "tokens=1-4 delims=/ " %%i in ('date /t') do set dtfile=%%l-%%j-%%k

On the server from which you will run the script open up a command prompt and issue the command:
date /t

to see what it returns. Mine gives:
Thu 12/09/2004

The FOR statement breaks apart that information and assigns it to the variables I through K. In my case that equates to:
I = Thu
J = 12
K = 09
L = 2004

Thus my DTFILE variable gets assigned, for today, 2004-12-09.

I would guess that your regional settings are different than mine, and so the order of the date fields is different. Once you figure out the order of the fields, you can then rearrange the assignment of the variables to DTFILE to get it in the format you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top