Solved

Batch file to Move and Zip and then FTP

Posted on 2011-03-13
2
750 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now