Processing indevidual a file get by ftp

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RMSoares
Posts: 32
Joined: 06 Aug 2012 12:01

Processing indevidual a file get by ftp

#1 Post by RMSoares » 20 Aug 2012 05:42

Hi,
I need to have a batch that via ftp get the files in a given directory, the files must be placed in a specific directory being processed each file individually.
The files have the following name format MYFILE_<DATE>_<ID>, and the DATE couldn't match the processing day and a number sequence ID generated by the application that creates the file.

This way I can have the same day the following files: MYFILE_20120801_32, MYFILE_20120817_45, MYFILE_20120820_18.

The files will be processed individually and should be renamed one at a time to the format MYFILE.dat and subsequently moved to a backup directory.
I need to have a script that performs the FTP the files in a given directory, importing a file each time, the examples listed above must begin by making the ftp file alphabetically (in this case the MYFILE_20120801_32), after having been ftp copy/rename the file to MYFILE.dat invoke the process of handling files (called MYPROCFILES) and then place the file (MYFILE_20120801_32) in a backup directory.

Someone can help me build a script that do ftp and individual processing of each file?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Processing indevidual a file get by ftp

#2 Post by foxidrive » 20 Aug 2012 07:04

If it possible to download all the files and then process them one at a time?

Are the files small or large in size?

What happens on the next run - will you process all the files again?

RMSoares
Posts: 32
Joined: 06 Aug 2012 12:01

Re: Processing indevidual a file get by ftp

#3 Post by RMSoares » 21 Aug 2012 08:59

Yes, it could be possible to get all the files and them process one by one. After get the files it must moved to a backup directory.

The files are small

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Processing indevidual a file get by ftp

#4 Post by foxidrive » 21 Aug 2012 23:07

Try this - it is untested. Alter the details near the top for folder and FTP details, and the backup folder near the bottom.

Code: Select all

@echo off
pushd "c:\files_storage\"
set server_name=FTP.server.name
set username=username
set password=password
set remote_directory=/folder/abc/def
set filespec=*.*

(
echo open %server_name%
echo %username%
echo %password%
echo cd %remote_directory%
echo mget %filespec%
echo quit
)>list.ftp

FTP -s:list.ftp
del list.ftp

for /f "delims=" %%a in (%filespec%) do (
copy /b "%%a" "Myfile.dat"
call MYPROCFILES.BAT
del "Myfile.dat"
move /y "%%a" "c:\backup directory"
)
popd

Post Reply