Hi. Thanks for your reply. Checking the logs on filezilla I can't see it failing to connect any time. It always seem to work.
the following code has been implemented:
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = server_address,
UserName = username,
Password = password,
PortNumber = port,
SshHostKeyFingerprint = "<fingerprint>"
};
Console.WriteLine("Uploading ADI => " + file_to_upload + ":" + Environment.NewLine +
"Host = " + server_address + Environment.NewLine +
"Username = " + username + Environment.NewLine +
"Port = " + port + Environment.NewLine +
"Destination folder = " + destination_folder);
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
transferOptions.FilePermissions = null;
transferOptions.PreserveTimestamp = false;
TransferOperationResult transferResult;
transferResult = session.PutFiles(file_to_upload, destination_folder, false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
session.Close();
session.Dispose();
}
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
}
}
The error received at seemingly random is:
Error: WinSCP.SessionRemoteException: Server unexpectedly closed network connection.
Authentication log (see session log for details):
Using username "<username>".
Authentication failed.
The server rejected SFTP connection, but it listens for FTP connections.
Did you want to use FTP protocol instead of SFTP? Prefer using encryption.
at WinSCP.SessionLogReader.Read(LogReadFlags flags)
at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
at WinSCP.CustomLogReader.WaitForNonEmptyElementAndCreateLogReader(String localName, LogReadFlags flags)
at WinSCP.Session.Open(SessionOptions sessionOptions)
at Script.Program.sftp_upload(String server_address, String username, String password, Int32 port, String file_to_upload, String destination_folder)
Any ideas?