Computing.Net > Forums > Programming > inserting word DELETE in a log file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

inserting word DELETE in a log file

Reply to Message Icon

Name: makutu
Date: February 5, 2009 at 06:14:24 Pacific
OS: Windows 2003
CPU/Ram: Intel 4 Gb
Product: Hewlett-packard / 3100
Subcategory: Batch
Comment:

Hi,

I have the following requirements to perform FTP file moves between two FTP servers, basically doing (PULL/GET and PUSH/PUT) of files.

The FTP Transaction consists of 4 Actions:

1. Get listing of remote files from remote FTP server and save listing to a file eg. ftplistfiles.log)

2. Copy list of remote files to the local ftp (eg. /localftp/incoming) folder until next scheduled batch run

3. Backup copied files to a separate folder
(eg. /localftp/incoming/backup-datetimestamp )

4. Delete list of files REMOTELY after action 1,2,3 is successful.

I HAVE DONE ACTIONS 1,2,& 3 SO FAR:
====================================
Action 1. Completed via batch file with sample following commands. Please note I'm a novice and just started learning batch file so forgive my syntax for obvious errors. This is just sample code as there was more code than shown below:

LIST.BAT
------------
@echo off
cmd.exe /c ftp -i -s:listing.scr > ftplistfiles.log

exit
------------

The contents of the ftplistfiles.log after performing an 'ls' command remotely via ftp listing.scr

C:\>type ftplistfiles.log
remotefile1.txt
remotereport2.pdf


Now, my question is how do you insert/prepend using Windows/DOS batch scripting the following ftp lines such as 'open ftp.remote.com' etc... and the word DELETE before the filename in the list of files in the ftplistfiles.log ?

Desired Content of transformed ftplistfiles.log should be something like after issuing 'type' command below:

C:\>type ftplistfiles.log
open ftp.remote.com
username
password
DELETE remotefile1.txt
DELETE remotereport2.pdf


The transformed file ftplistfiles.log will be used as ftp input script to the ftp command to DELETE remote files. As in:

ftp -i -s:ftplistfiles.log


I even used something like:

FOR /F "tokens=2* delims=." %%A IN ('type ftplistfiles.log') DO echo (set _delete.%%A)

set _delete.=

But I was getting notdefined environment vars. _delete.<filename> even though the variable was set.

Any help or directions on how to do achieve ACTION4-delete remote files, is very much appreciated as I'm stuck on the last action.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: February 5, 2009 at 12:37:43 Pacific
Reply:

To turn this:

open ftp.remote.com
username
password
remotefile1.txt
remotereport2.pdf

into this:

open ftp.remote.com
username
password
DELETE remotefile1.txt
DELETE remotereport2.pdf
====================================
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (myfile) do (
set /a N+=1
if !N! gtr 3 (
echo DELETE %%a >> newfile
) else (
echo %%a >> newfile
)
)
=========================================
To make it really spiffy for use as a ftp scr, add this as the very last line [outside the for loop]

echo bye >> newfile


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

M2


0

Response Number 2
Name: makutu
Date: February 6, 2009 at 15:44:53 Pacific
Reply:

G'day M2,

Thanks heaps for the code logic! You really saved my day. I did some modification as it was displaying the filename of the ftp log file instead of the its filename contents. I had to prime the input file to insert the first three ftp command lines before going into the FOR loop. But overall it did the transformation I wanted with just some minor bug to clean up. Again Thank you for your assistance. Btw, if you happen to visit Melbourne, Australia I'll be happy to tour you around and it's my shout.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: inserting word DELETE in a log file

How to delete first for lines in a txt file www.computing.net/answers/programming/how-to-delete-first-for-lines-in-a-txt-file/20172.html

VBScript help creating a log file www.computing.net/answers/programming/vbscript-help-creating-a-log-file-/14414.html

How to Do this in a Script File www.computing.net/answers/programming/how-to-do-this-in-a-script-file/17099.html