Computing.Net > Forums > Windows 2000 > Batch file to build a script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch file to build a script

Reply to Message Icon

Name: ikerstges
Date: January 4, 2005 at 00:44:19 Pacific
OS: Windows 2000
CPU/Ram: PIII650/512
Comment:

Hi all,

I would like to create a batchfile that basically builds an ftp-script.

I have a basic textfile called "ScriptFile.ftp" containing the lines to login to the ftp-server and set directories properly. To that file I want to add (or better: insert) lines to take care of uploading a specific file and then rename the file on the ftpserver after upload succeeded.

For the file: "example_01.xml" I would need to have following lines in the script:

put example_01.xml
rename example_o1.xml example_o1.xml.OK

But I have to process an undefined amount of files, so this needs to loop for ALL the files in the specified directory. So when I have example_01.xml and example_02.xml until example_nn.xml I would need a for statement and redirect the results into my file "ScriptFile.ftp".

When I use:

For /F "tokens=*" %%A in ('Dir /B /A:-D %1') Do (
echo %%~fA >> ScriptFile.ftp
)

My "ScriptFile.ftp" would look like:

open servername
username
userpass
lcd c:\upload
cd /ftplocation
example_01.xml
example_02.xml
example_nn.xml

How could I make the file become like this:

open servername
username
userpass
lcd c:\upload
cd /ftplocation
put example_01.xml
rename example_01.xml example_01.xml.OK
put example_02.xml
rename example_01.xml example_02.xml.OK
put example_nn.xml
rename example_nn.xml example_nn.xml.OK

I hope that I'm clear about my request. If you still have questions, please let me know and I will try to respond and hopefully get this solved?!

Thanks in advance!
Igor.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 4, 2005 at 01:17:44 Pacific
Reply:

Hi Igor,

Well, for starters, there's a neat litlle utility to prefix a string to every line in a file.

So in the case of the lines where you need to put files, since you already figured out how to do the for in a bat, once you generate a file with the names to put, let's say it's putlist.txt, you can:

prefix "put " <putlist.txt>newput.txt

I put the prefix util here:

http://www.golden-triangle.com/PREFIX.COM

[349 bytes; ain't real programming wonderful?]

I think it'll be easier to do all the puts in a block and all the renames in another block.

I'm still thinking about how to generate the rename section.

I guess I'm not supposed to ask why you don't copy or rename the files before ftp xfer.

HTH


M2


0

Response Number 2
Name: ikerstges
Date: January 4, 2005 at 02:33:07 Pacific
Reply:

This "PREFIX.COM" is a neat util! Thanks for that!

The reason for my approach is to be absolutely sure that an upload to the FTP-server can finish BEFORE a process on the other side can 'see' the file. In my example, the file "example_01.xml" will not be recognised by the process, but as sson as the file is renamed into "example_01.xml.ok" the process will start (and this way Im sure that the file is completely uploaded).'

I'm still puzzled how to use the "PREFIX.COM" to produce lets say two files: "newput.txt" and "newrename.txt" and then later use these to construct the lines into my ftp-script. I will keep puzzling and meanwhile keep an eye to this post!

Later!
Igor.


0

Response Number 3
Name: Mechanix2Go
Date: January 4, 2005 at 02:58:22 Pacific
Reply:

Hi Igor,

You can use this to generate a block with the the old and new filenames:

@echo off > quit.bat

:: This takes a filename as input and puts the orig and one
:: with .OK appended into a file.

if %1'==' quit
echo %1>tmp.###
set /p xname=<tmp.###
echo %xname% %xname%.OK >> OKblock.txt


::=================

Then just prefix your "rename " and you should have a block you can slap into your script.

HTH

M2


0

Response Number 4
Name: Mechanix2Go
Date: January 5, 2005 at 01:34:33 Pacific
Reply:

Hi Igor,

I must ahve been having a "senior moment."

This will work even better:
::====
@echo off > quit.bat

:: This takes a filename as input and puts the orig and one
:: with .OK appended into a file.

if %1'==' quit
echo %1>tmp.###
set /p xname=<tmp.###
echo rename %xname% %xname%.OK >> OKblock.txt
::=====

HTH

M2


If at first you don't succeed, you're about average.


0

Response Number 5
Name: ikerstges
Date: January 21, 2005 at 08:02:37 Pacific
Reply:

Thanks for your prompt followup M2Go! Much appreciated!!!

I have chosen to use following configuration, which works very well:

I have a script called [Customer_Name].ini with contents:
open [ftp_servername]
Username
pass
lcd [Drive]:\Live\Customer\[Customer_Name]\export
cd //[ftp_directory]
!!!!empty line!!!

---------

Then, a batchfile will use this file and update with information from the directory list in the 'for' loop:

::This part will take care of creating the ftp-script for each file in the specified directory
---------
copy V:\Live\Customer\[Customer_Name]\scripts\[Customer_Name].ini V:\Live\Customer\[Customer_Name]\scripts\Status_Update.ftp /y
V:
cd\Live\Customer\[Customer_Name]\export
For /F "tokens=*" %%A in ('Dir STS*.xml /B /A:-D %1') Do (
echo put %%~fA >> V:\Live\Customer\[Customer_Name]\scripts\Status_Update.ftp
echo rename %%A %%A.OK >> V:\Live\Customer\[Customer_Name]\scripts\Status_Update.ftp
)
echo quit >> V:\Live\Customer\[Customer_Name]\scripts\Status_Update.ftp


0

Related Posts

See More



Response Number 6
Name: ikerstges
Date: January 21, 2005 at 08:04:33 Pacific
Reply:

Sorry.... one error in previous post;

copy V:\Live\Customer\[Customer_Name]\scripts\[Customer_Name].ini V:\Live\Customer\[Customer_Name]\scripts\Status_Update.ftp /y

Should have been:

copy V:\Live\Customer\[Customer_Name]\scripts\[Customer_Name].ini V:\Live\Customer\[Customer_Name]\scripts\[Customer_Name].ftp /y


0

Sponsored Link
Ads by Google
Reply to Message Icon

transfer file through par... Run multiple instances of...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 2000 Forum Home


Sponsored links

Ads by Google


Results for: Batch file to build a script

BATCH FILE TO LAUNCH DIAL-UP CONNECTION www.computing.net/answers/windows-2000/batch-file-to-launch-dialup-connection/25271.html

Batch file to delete the temp files www.computing.net/answers/windows-2000/batch-file-to-delete-the-temp-files/33636.html

How to write a script to change clock www.computing.net/answers/windows-2000/how-to-write-a-script-to-change-clock/32360.html