Solved

Batch file to Move and Zip and then FTP

Posted on 2011-03-13
2
754 Views
Last Modified: 2012-05-11
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
Comment
Question by:vourneenward
2 Comments
 
LVL 30

Accepted Solution

by:
Mike Lazarus earned 500 total points
ID: 35127531
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
 
LVL 16

Expert Comment

by:AlexPace
ID: 35130438
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question