Topic "Sftp unstable"

Author Message
MrKitchy

Guest


Hi.

I have set up, in c#, code to upload one single xml file to a remote sftp server. However it seems to be random if it's successful or not. Often trying to run the upload it reports that connection has been refused because it seems to be ftp not sftp. However trying again 5 minutes later, it transfers the file fine.

First I had the idea that the session never disconnects from the server and this was locked for login again until timeout. I added session.close() to close the connection without any luck. However I am unsure if this actually disconnects the session. This is a c# cli script which runs several times during an hour.

Transferring with Filezilla never causes this issue. I can also connect with several instances to the server without issues.

Is the api itself somehow denying me to use the code again unless some one has gone by?

Thanks.

So, any idea what's going on?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26108
Location: Prague, Czechia
Sorry, but this is too vague.

Though to give you some information:

- There's nothing that would prevent you from using the assembly frequently.
- If you get "connection refused" from the server, it's the server that refuses the connection, that has nothing to do with WinSCP.
- Of course, the problem can be that you do not close the previous connections (what makes the server refuse you to open another one).
- FileZilla may retry unsuccessful connection, without you noticing it. Double check its log.
MrKitchy

Guest


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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26108
Location: Prague, Czechia
Show us a log file both from WinSCP .NET assembly and FileZilla.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License