Topic "Newbie Help - Delete files older than "n" days using C#"

Author Message
albogado
[View user's profile]

Joined: 2014-12-16
Posts: 2
Location: Chicago
Hello,
I am looking for some assistance in regards to getting some automated file deletions to occur via a program. To be more specific I am looking to do the following;

1) login to device
2) search for specific filenames older than "n" days;
3) delete files

As I am new to C# I am having some difficulty in understanding how to do this. I am able to successfully login to the appliance in question but I'm lost on how to proceed from here. Is there anyone here that could provide some help or provide some examples on how to do items (2) and (3) as aforementioned above? Thanks!

This code is working for login;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinSCP;

namespace WinSCPTest
{
class Program
{
public static int Main()
{

{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "hostname.host.com",
UserName = "user",
Password = "yEalB",
SshHostKeyFingerprint = "ssh-rsa 2048 a9:86:dc:0b:8f:e4:70:f1:dc:0d:26:3b:94:4f:52:41"
};
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Use Session.ListDirectory.
http://winscp.net/eng/docs/library_session_listdirectory

Iterate returned list of files and look for old files using RemoteFileInfo.LastWriteTime.
http://winscp.net/eng/docs/library_remotefileinfo

Call Session.RemoveFiles for every matching file.
http://winscp.net/eng/docs/library_session_removefiles
albogado
[View user's profile]

Joined: 2014-12-16
Posts: 2
Location: Chicago
Thank you, this information is helpful. Hopefully I can get this working and share my code with the community. Thanks again!
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License