[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 760
  • Last Modified:

Batch file to Move and Zip and then FTP

I need to write a batchfile to do the following:

-Move a set of files based on date from A to B.
-Delete the files in A.
-Zip these "moved" files in B.
-Delete the files in B (except Zipped file).
FTP the zip file to a FTP site.
0
vourneenward
Asked:
vourneenward
1 Solution
 
Mike LazarusAct! Evangelist - CRM ConsultantCommented:
With WinRAR, you can create a Profile or command lines that would grab the files ( based on date) in A directly, store the compressed file in B, test the compressed file against the original, add a CRC check, then delete the files from A (skipping the copy from A to B first)

Then use a BAT file that runs the WinRAR Profile and uses DOS FTP to upload the created file.

You may want to add a function that checks that the files are not open (in use) first
0
 
AlexPaceCommented:
Robo-FTP is good for automating files transfer jobs like this one where files are deleted because it has the ability to do error handling.  Here is a sample Robo-FTP command script that does basically what you need... at least as I understand it..  Notice it checks for an error after any command where a failure could cause you a big problem and it jumps to the bottom without doing the deletions and the remainder of the script.  Obviously you could design something cooler where it took different steps based on the specific type of error or you could make it email someone to report the error, that sort of thing.  
:enable_logs
log "ftp_archive_script.log"
TRACELOG "ftp_archive_trace.log"

:assign_values
SET source = "c:\data\source"
SET archive = "c:\data\old_files"
SET days_back = 14

:init
WORKINGDIR archive
IFERROR!= $ERROR_SUCCESS GOTO halt_process
WORKINGDIR source
IFERROR!= $ERROR_SUCCESS GOTO halt_process
set archive_date = %date
DATESUB archive_date days_back 

:file_loop_top
GETFILE "*"
IFERROR!= $ERROR_SUCCESS GOTO ftp_zip
IFDATE< %nextfiledate archive_date GOTO move_file
GOTO file_loop_top
:move_file
MOVE %nextfile archive
IFERROR!= $ERROR_SUCCESS GOTO halt_process
GOTO file_loop_top

:ftp_zip
WORKINGDIR archive
DELETE "archive.zip"  ;; get rid of old archive
ZIP "archive.zip" "*" /create
IFERROR!= $ERROR_SUCCESS GOTO halt_process
FTPLOGON "127.0.0.1" /user=MyUserName /pw=Secret
IFERROR!= $ERROR_SUCCESS GOTO halt_process
SENDFILE "archive.zip" 
IFERROR!= $ERROR_SUCCESS GOTO halt_process
FTPLOGOFF
DELETE "*"

:halt_process
STOP  ;; change to EXIT when running as a service

Open in new window

Robo-FTP is not really an FTP client as much as it is a development environment for file transfer automation. Its not free but it isn't terribly expensive for most companies considering how much time it can save.  You can download a 30-day trial from their web site.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now