Avatar of ocamporuss
ocamporuss
 asked on

Delete files on ftp server

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.
Visual Basic.NET

Avatar of undefined
Last Comment
ocamporuss

8/22/2022 - Mon
andygrant2005

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.
SOLUTION
guvera

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ocamporuss

ASKER
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.
PaulNSW

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ocamporuss

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