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?
Processing indevidual a file get by ftp
Moderator: DosItHelp
Re: Processing indevidual a file get by ftp
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?
Are the files small or large in size?
What happens on the next run - will you process all the files again?
Re: Processing indevidual a file get by ftp
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
The files are small
Re: Processing indevidual a file get by ftp
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