[Webinar] Streamline your web hosting managementRegister Today

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

FTP mget files and delete them after "getting" them

I need a batch script that will download multiple files from a remote (unix) site.  The catch is I need to safely delete those that I download safely.  How do I do that?  

I have to use a batch file.  My script so far is attached:
@echo off
setLocal EnableDelayedExpansion
 
> #.ftp echo o 10.150.10.10
>> #.ftp echo ubuntu
>> #.ftp echo ubunutu123
>> #.ftp echo bin
>> #.ftp echo cd /ftpbat
>> #.ftp echo prompt
>> #.ftp echo mget *.abc
>> #.ftp echo bye
 
ftp -s:#.ftp

Open in new window

0
dbdp
Asked:
dbdp
1 Solution
 
Gary DewrellSenior Network AdministratorCommented:
The delete command is what would be used but I think you are wanting to insure the file was actually downloaded successfully and then delete it?  

I found this article that may get you started in the right direction.

http://www.robvanderwoude.com/ftp.php
0
 
KechkaCommented:
Try this

open 10.150.10.10
ubuntu
ubuntu123
cd /ftpbat
bin
prompt n
mget *.abc
mdelete *.abc


name the file test.scr and run like
ftp -s:test.scr

0
 
dbdpAuthor Commented:
I must ensure that files are downloaded before deleting them
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
KechkaCommented:
I will check, but you can create two scripts one for download, other for delete, run other 1 hour later..
0
 
KechkaCommented:
If you try my script you will notice that the mdelete command is not executing until transfer ends.
0
 
berniemurcianoCommented:
depending on your ftp implementation, I use ws ftp and the script allows for error catching

on error goto end
mget *
mdelete *

so if there is an error in the mget the mdelete won't get executed, the catch is that new files may arrive while processing the mget and those new ones may get deleted. I recommend to get an FTP library and have programmatic control where you download the files, list and compare your local and host and then safely delete
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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