Computing.Net > Forums > Programming > script to delete files after ftp

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

script to delete files after ftp

Reply to Message Icon

Name: gnussbaum
Date: March 23, 2009 at 06:29:38 Pacific
OS: Windows 2003
Subcategory: Batch
Comment:

Hi,

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 24, 2009 at 00:01:28 Pacific
Reply:

untested
================================
:: checks to see if files in mylist got ftp'd
:: if so, delets local files

@echo off

> ft.do echo o mysite.com
>> ft.do echo user
>> ft.do echo pass
>> ft.do echo bin
>> ft.do echo ls
>> ft.do echo bye

ftp -s:ft.do > 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.

M2


0

Response Number 2
Name: ghostdog
Date: March 24, 2009 at 00:06:37 Pacific
Reply:

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):
    try:
        ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
    except Exception,e:
        print "Error uploading. ",e  #check upload error message
os.chdir("localpath")
ftp = FTP('localhost')
ftp.set_debuglevel(3)
try:
    ftp.login("") 
except Exception, e:
    print "error ",e
else:
    for files in os.listdir("."):
        if os.path.isfile(files):
            upload(ftp,files)
    
    


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: script to delete files after ftp

unable to delete file with wildcard www.computing.net/answers/programming/unable-to-delete-file-with-wildcard/16591.html

VB Script for deleting files www.computing.net/answers/programming/vb-script-for-deleting-files-/16904.html

Batch Script to delete '?' character in txt www.computing.net/answers/programming/batch-script-to-delete-character-in-txt/19908.html