Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.OKBut 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.xmlHow 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.OKI 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.

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

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.

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

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.

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

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

![]() |
transfer file through par...
|
Run multiple instances of...
|

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