Delete files on ftp server

ocamporuss
ocamporuss used Ask the Experts™
on
Greetings,

I have created a program using vb.net which allows users to upload files on an ftp server and share them via a link that the program generates at the end of the upload.

To save space on my ftp server, I will only be keeping the uploaded files for a set time (in this case 7 days) and would delete files older than that.

For that I am creating a separate program (still using vb.net) that will run unattended on my PC. I am aiming for this to check the ftp server every now and then, check all existing files at that moment and see if they are 7 days or older then delete such files.

Unfortunately, I cannot seem to find a way to "detect" the date the file was uploaded (modified date) and run a procedure to check if it is already more than 7 days old.

I have used the function WebRequestMethods.Ftp.ListDirectoryDetails but it returns strings which I have no way of isolating the file date (and it also does not provide the year, which would be a problem to compute how old the file is if it was uploaded towards the end of the year)

Any suggestions on how I can get about deleting files on my ftp server that are a certain amount of days old?

Thank you and regards.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I'll be totally honest here and say I have never had to get the modified date of a file on an FTP platform before, but the code I use to find the file modified date on your local file system is :


FDate = IO.File.GetLastWriteTime(FName)


I can see no reason why this wouldn't work for you.

Let me know how it goes.
Commented:
dude,

Please find the below link. It seems look like your problem.

http://winhlp.com/node/468

Thanks
Guvera
Most Valuable Expert 2012
Top Expert 2014
Commented:
This guy managed to parse the dates.

http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/b775c23c-29a8-436a-9d28-a338b35a5c3a/


Another option is to have a database file which contains the file names and datetime it was uploaded. You insert a record into this DB everytime a file is uploaded. Then the deleting program can run a simple query on this DB to get all the files older than 7 days and directly delete them rather than going through each file.
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

or you could just use ZendTo http://zend.to

Author

Commented:
Thank you all for your feedback.

@andygrant2005: Please correct me if I am wrong, but taking the date from a local file would mean I would have to download all the existing files on the ftp server to my PC first before I could check each of them out. Given that my program would be used by 200+ people in my company, there would be a lot of files at any given time and it may not be feasible for me to do so in my situation.

@guvera: Looking at the link you have provided, I assume that this is a script that runs on the ftp server itself. This may be my fallback if I am unable to actually to do what I wanted to using my second program. This is because my file upload program has the capacity to upload to several ftp servers that our company has for redundancy purposes. And to have to configure each server may be more complicated for me (as i have never done it before) than to have a program do it for me irrespective of the server.

@CodeCruiser: The link you have provided looks promising. I will give it a try and see how it goes.

@PaulNSW: It is feasible for me on my own to create an account with Zendto or with any other free/paid web-based file sharing system. But I think (and this goes with my current company) that most businesses with enough resources would rather keep their files managed by themselves rather than have a third party do it instead.

Thank you and regards.
ZendTo is a free software product that you deploy on your own server, it is not a 3rd party service/intermediary. Your files are hosted on whatever server/VM you have in your environment, as is the ZendTo server.  You have full control over who has access, whether it links in with your AD domain, when files are automatically deleted, the maxium file size a user can send, whether you use SSL etc

Author

Commented:
Dear All,

Sorry for the delayed response.

@PaulNSW: Thank you for clarifying. I have taken a deeper look at ZendTo and have decided to make it as my fallback should I be unable to do what I would like with my program.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial