HINT: How to delete all files from remote dir (General questions)

by Jasmine, (7625 days ago)

Info applies to wodSFTP.NET and C#.

This code will delete all files from remote folder. It uses Blocking mode, but can be easily changed in async behavior. You can apply this to almost any other operation that deals with many files - first get list of files, then loop through the list for each file. Should be easy to change to VB.NET and other languages.

[code]
public static System.Collections.SortedList names;
static void Main(string[] args)
{
SFTP sftp = new SFTP();
sftp.AttributesDataEvent += new WeOnlyDo.Client.SFTP.AttributesDataDelegate(sftp_AttributesDataEvent);

sftp.Hostname = ... ;
sftp.Login = ... ;
sftp.Password = ... ;
sftp.Blocking = true;
sftp.Connect();

names = new System.Collections.SortedList();
try
{
sftp.ListAttributes( /tmp );
}
catch (Exception)
{}

while (names.Count>0)
{
sftp.DeleteFile( /tmp/ + names[0]);
names.RemoveAt(0);
}

// optionally we can remove this dir also
// sftp.RemoveDir( /tmp );

sftp.Disconnect();
}

private static void sftp_AttributesDataEvent(object Sender, WeOnlyDo.Client.SFTP.AttributesArgs[] Args)
{
for (int i=0;i<Args.Length;i++)
{
names.Add(i, Args.Name);
}
}
[/code]

locked

Re: HINT: How to delete all files from remote dir

by Vishwajit Girdhari @, (7562 days ago) @ Jasmine

Hey thanks for this hint.
I was looking for implementing it and found it here just-in-time.
It would be great if you could post more
sample codes in C#

Liked you your approach for building the filelist using AttributesDataDelegate , I was fidling with ListItemsReceived event.

Expecting more Tips and Hints from wodSupport.

Vishwajit Girdhari
[url=http://]http://vishwajit.cjb.net[/url]

locked

Re: HINT: How to delete all files from remote dir

by Vishwajit @, (7562 days ago) @ Vishwajit Girdhari

test...
now i am registered member of this forum ... :-)

locked