Solved

Batch file to Move and Zip and then FTP

Posted on 2011-03-13
2
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

690 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