After my Windows service has been running successfully for a few days I get a corrupt memory error from Rebex sFTP. The error then recurs whenever I try to use Rebex and I have to restart the service.
Is there something I'm doing wrong? I'm using Dispose(), not Disconnect(). And I'm creating a new connection on every operation, rather than trying manage a permanently open connection.
I'd appreciate any suggestions.
Here's the error:
System.AccessViolationException:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at gbMKS.1vL03D.1fZglFZ(String )
at gbMKS.ULE4T.1fZglFZ(IAsyncResult , String , Int32 )
at gbMKS.ULE4T.1QP6MBZ(IAsyncResult , Int32 )
at Rebex.Net.ProxySocket.Connect(String serverName, Int32 serverPort)
at Rebex.Net.Sftp.Connect(String serverName, Int32 serverPort, SshParameters parameters)
at Rebex.Net.Sftp.Connect(String serverName, Int32 serverPort)
at Helper.FTPHelper.GetSFTPAndLogin()
at Helper.FTPHelper.GetFileNamesInFolder(String path)
at Helper.FileMoverHelper.DeleteFilesInFolderOlderThan(String folder, Int32 days, ILog logger)
And here's some sample code:
public void DeleteFiles(string folder, ILog logger)
{
try
{
var files = GetFileNamesInFolder(folder);
foreach (var file in files)
{
var time = GetFileDateTime(file));
DeleteIfExists(file, folder);
}
}
catch (Exception e)
{
logger.Error("Couldn't clear folder : " + folder, e);
System.Threading.Thread.Sleep(60000);
}
}
public List<string> GetFileNamesInFolder(string path)
{
var results = new List<string>();
using (var sftp = GetSFTPAndLogin())
{
sftp.ChangeDirectory(path);
var items = sftp.GetList();
foreach (var item in items)
{
if (item.IsFile)
results.Add(item.Name);
}
}
return results;
}
private Sftp GetSFTPAndLogin()
{
var sftp = new Sftp();
sftp.Timeout = 30000;
if (UseHTTPProxy)
sftp.Proxy = new Proxy(ProxyType.HttpConnect, ProxyAuthentication.Ntlm, ProxyHostname, ProxyPort, CredentialCache.DefaultNetworkCredentials);
sftp.Connect(Hostname, Port);
sftp.Login(Username, Password);
return sftp;
}