Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have SFTP server which is able to connect via (Bitvise SSH client) with the help of Obfuscation Password. But, unable to connect the same via c# code.

Here is my code:

winSCPSrc.SessionOptions sessionOptionss = new winSCPSrc.SessionOptions();
sessionOptionss.Protocol = winSCPSrc.Protocol.Sftp;
sessionOptionss.PortNumber = Port;
sessionOptionss.HostName = Host;
sessionOptionss.UserName = Username;
if (!string.IsNullOrEmpty(Password))
{
sessionOptionss.Password = Password;
}
//sessionOptionss.GiveUpSecurityAndAcceptAnySshHostKey = true;
sessionOptionss.SshHostKeyFingerprint = fingerPrint;

using (winSCPSrc.Session session = new winSCPSrc.Session())
{
State.KPILog.Info(" SFTP Connection trying to Open ");
session.AddRawConfiguration("DefaultConfiguration", "false");
// Connect
session.Open(sessionOptionss);
State.KPILog.Info("SFTP Connection Open ");
winSCPSrc.TransferOptions transferOptions = new winSCPSrc.TransferOptions();
transferOptions.TransferMode = winSCPSrc.TransferMode.Binary;
// transferOptions.SpeedLimit = 100;
winSCPSrc.TransferOperationResult transferResult;


I'm getting "Server unexpectedly closed network connection" error while session.Open(sessionOptionss)


Please let me know there is any other dll available other than winscp to connect SFTP.

What I have tried:

Able to connect and download files via bitvise SSH client but unable to implement it in C# code.

Out IT provider has given some "Obfuscation Password" for connecting via bitvise ssh client. I have no idea how it works in c# code
Posted
Updated 19-Jul-21 21:26pm
v2
Comments
Richard Deeming 19-Jul-21 7:44am    
There's a secret error somewhere in your secret code. You need to fix that.

Seriously, how do you expect anyone to help you fix an error in code we can't see, when the only description of the problem is "it is not working"?!

Click the green "Improve question" link and update your question to include a proper description of the problem, the relevant parts of your code, and the full details of any error(s). If possible, include the relevant parts of the connection logs for the successful and failed connections, remembering to obfuscate any sensitive information.
Member 15294207 20-Jul-21 3:27am    
Thanks for your response, i have updated question. May be now you will understand my situation.
SeeSharp2 19-Jul-21 8:08am    
How can we help?
Member 15294207 20-Jul-21 3:28am    
updated question with code

It is a bad security practice to use SSH passwords, particularly for automation, use SSH keys instead.
 
Share this answer
 
I have used Renci.SSh.Net and it is very easy. More about this and some alternatives can be found here, c# - SFTP Libraries for .NET - Stack Overflow[^].

You may be using a wrong port number or wrong credentials or the url may be incorrect. Or it may require a certificate. No way for us to know.
 
Share this answer
 
Comments
Member 15294207 20-Jul-21 11:53am    
I'm in a hectic situation of download files from bitvise SFTP server only, did not possible to use Renci.SSh. because SFTP server already setup using bitvise. only one option is to implement SFTP using FlowSsh library which owned by Bitvise
SeeSharp2 20-Jul-21 12:21pm    
They must not support standard sftp then. Then you'll probably have to contact Bitvise. I've never heard of them.
Member 15294207 21-Jul-21 12:34pm    
ok, thank you for the response

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900