Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Batch file to Move and Zip and then FTP

Posted on 2011-03-13
2
Medium Priority
?
758 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
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…
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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