I'm trying to upload a file using SSH.NET using C# in a .NET Framework 4.5.2 project.
As soon as the ConnectionInfo
constructor is invoked the application exits without any Exception not error message.
The event viewer is clean.
It seems I'm running into an AccessViolationException
, that I know it's a serious problem and cannot be caught inside managed code but...
What am I doing wrong in using this library?
I just need to upload my file to a SFTP server.
Here is my code:
public override void Upload(FtpConfiguration conf, string file)
{
var fi = new FileInfo(file);
try
{
// As soon as code reach this line the application crashes
var connectionInfo = new ConnectionInfo(conf.Server,
conf.Username,
new PasswordAuthenticationMethod(conf.Username, conf.Password)
);
using (var sftp = new SftpClient(connectionInfo))
{
sftp.Connect();
if (sftp.IsConnected)
{
if (!string.IsNullOrEmpty(conf.Subfolder))
sftp.ChangeDirectory(conf.Subfolder);
using (var fileStream = new FileStream(fi.FullName, FileMode.Open))
{
sftp.UploadFile(fileStream, fi.Name, null);
}
sftp.Disconnect();
}
}
}
catch (Exception ex)
{
// Just for debug purpose
var error = ex.Message;
throw ex;
}
}