FTP mget files and delete them after "getting" them

Posted on 2009-04-23
Last Modified: 2013-11-29
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

>> #.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

Question by:dbdp
    LVL 12

    Expert Comment

    by:Gary Dewrell
    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.
    LVL 10

    Expert Comment

    Try this

    cd /ftpbat
    prompt n
    mget *.abc
    mdelete *.abc

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


    Author Comment

    I must ensure that files are downloaded before deleting them
    LVL 10

    Accepted Solution

    I will check, but you can create two scripts one for download, other for delete, run other 1 hour later..
    LVL 10

    Expert Comment

    If you try my script you will notice that the mdelete command is not executing until transfer ends.

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    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…
    SSL is a very common protocol used these days when browsing the web.  The purpose is to provide security to communication, but how does it do it?  There are several pieces at work that have to be setup before SSL will even work and it requires both …
    Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

    794 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

    15 Experts available now in Live!

    Get 1:1 Help Now