script to delete files after ftp

March 23, 2009 at 06:29:38
Specs: Windows 2003

I'm trying to have a .bat file set up as a scheduled task to upload files via ftp and then, if successful, delete the files locally. I have the automated upload set up correctly, but am having difficulty trying to figure out how to check if the FTP upload was successful and then delete locally.

I'm also open to other scripts to do this in Scheduled Tasks.

Any ideas?

See More: script to delete files after ftp

Report •

March 24, 2009 at 00:01:28
:: checks to see if files in mylist got ftp'd
:: if so, delets local files

@echo off

> echo o
>> echo user
>> echo pass
>> echo bin
>> echo ls
>> echo bye

ftp > filelist

for /f "tokens=* delims= " %%a in (mylist) do (
find /i "%%a" < filelist > nul
if not errorlevel 1 del %%a

If at first you don't succeed, you're about average.


Report •

March 24, 2009 at 00:06:37
if you want to have better error control for FTP process, its better off using dedicated ftp libraries which you can find in languages such as Perl/Python. here's an example Python script. Its not a full solution to your problem, but just to illustrate the idea.
from ftplib import FTP
import os
def upload(ftp, file):
        ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
    except Exception,e:
        print "Error uploading. ",e  #check upload error message
ftp = FTP('localhost')
except Exception, e:
    print "error ",e
    for files in os.listdir("."):
        if os.path.isfile(files):

Report •

Related Solutions

Ask Question