HINT: How to delete all files from remote dir (General questions)
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]
Complete thread:
- HINT: How to delete all files from remote dir - wodSupport, 2004-06-15, 22:30
- Re: HINT: How to delete all files from remote dir - Vishwajit Girdhari, 2004-08-17, 06:58
- Re: HINT: How to delete all files from remote dir - Vishwajit, 2004-08-17, 07:07
- Re: HINT: How to delete all files from remote dir - Vishwajit Girdhari, 2004-08-17, 06:58