Click here to Skip to main content
16,016,568 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
iam creating c# application to upload file from local to SFTP, But it couldnt connect to sftp and it throws an exception

After searching all website, they said to install DiffieHellman and Org.Mentalis.Security.

Even after installing these 2 dll, iam getting same error.

i have given my sample code below

string _ftpURL = "jtend";
             string _UserName = "kascope";
             string _Password = "S@ssw0rd813";
             int _Port = 22;
             string _ftpDirectory = @"/";
             string LocalDirectory = @"E:\To_Upload";
             string FileName = "tests.xls";

             Sftp oSftp = new Sftp(_ftpURL, _UserName, _Password);
             oSftp.Connect(_Port); // Throws Error here
             string LocalDirectory1 = LocalDirectory + "/" + FileName;
             string ftpDirectory = _ftpDirectory + "/" + FileName;
             oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
             oSftp.Close();


Error:

Session.connect: System.IO.FileLoadException: Could not load file or assembly 'DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=4ed5f4288b4076af' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=4ed5f4288b4076af'
at Tamir.SharpSsh.jsch.jce.DH.getE()
at Tamir.SharpSsh.jsch.DHG1.init(Session session, Byte[] V_S, Byte[] V_C, Byte[] I_S, Byte[] I_C)
at Tamir.SharpSsh.jsch.Session.receive_kexinit(Buffer buf)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)

=== Pre-bind state information ===
LOG: DisplayName = DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=4ed5f4288b4076af
(Fully-specified)
LOG: Appbase = file:///D:/vinodh/Workout/SFTP_SharpSSH/SFTP_SharpSSH/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Tamir.SharpSsh, Version=1.1.1.13, Culture=neutral, PublicKeyToken=4ed5f4288b4076af.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\vinodh\Workout\SFTP_SharpSSH\SFTP_SharpSSH\bin\Debug\SFTP_SharpSSH.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: DiffieHellman, Version=0.0.0.0, Culture=neutral, PublicKeyToken=4ed5f4288b4076af
LOG: Attempting download of new URL file:///D:/vinodh/Workout/SFTP_SharpSSH/SFTP_SharpSSH/bin/Debug/DiffieHellman.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

What I have tried:

<pre>   string _ftpURL = "jtend";
                string _UserName = "kascope";
                string _Password = "S@ssw0rd813";
                int _Port = 22;
                string _ftpDirectory = @"/";
                string LocalDirectory = @"E:\To_Upload";
                string FileName = "tests.xls";    

                Sftp oSftp = new Sftp(_ftpURL, _UserName, _Password);
                oSftp.Connect(_Port); // Throws Error here
                string LocalDirectory1 = LocalDirectory + "/" + FileName;
                string ftpDirectory = _ftpDirectory + "/" + FileName;
                oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
                oSftp.Close();
Posted
Updated 5-Oct-17 6:43am
Comments
ZurdoDev 5-Oct-17 10:31am    
It cannot find the dll or the right version of the dll.

The relevant part of the error message would seem to be:
Quote:
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN

The assembly you've downloaded doesn't match the assembly that Tamir.SharpSsh was compiled against.

If you can't find a matching version of the assembly, you'll need to download the source[^] and recompile it against the new version of the DiffieHellman assembly.
 
Share this answer
 
First of all, have you added them as references to your project? If you have added them as references, have you made sure that you have set them to be copied to the output directory? Does diffiehelman have any dependencies that you need to copy across as well? It might come with a runtime installer that you need to run on your clients to ensure that all the dependencies are installed.
 
Share this answer
 

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