SSH / SFTP connection issue using Tamir.SharpSsh

26,735

Solution 1

Without looking at your log files it is hard to tell what the issue is.

However keep in mind that SCP is not SFTP - they are completely different protocols that run over SSH. It is possible that your SFTP does not actually support SCP - not all SFTP servers do. CoreFTP may be using SFTP.

Our commercial package, edtFTPnet/PRO, might also be worth trying, if only as an alternative to try to get a different client working against your server.

Solution 2

I use Tamir.SharpSSH - latest version 1.1.1.13

This has a class SFTP. You can use this class directly to do SFTP instead of using JSch, Session class.

Quick Sample here:

127.0.0.1 - Server IP

/SFTPFolder1/SFTPFolder2 - Server Location Where I want my files to go

        Sftp sftpClient = new Sftp("127.0.0.1", "myuserName", "MyPassword");

        sftpClient.Connect();

        sftpClient.Put(@"C:\Local\LocalFile.txt", "/SFTPFolder1/SFTPFolder2");

Let me know if you have any issues.

Share:
26,735
jinsungy
Author by

jinsungy

Engineering Manager with Full-Stack Development experience in .NET, MS SQL Server.

Updated on November 17, 2020

Comments

  • jinsungy
    jinsungy over 3 years

    This is my code to connect and send a file to a remote SFTP server.

    public static void SendDocument(string fileName, string host, string remoteFile, string user, string password)
            {            
                Scp scp = new Scp();
    
                scp.OnConnecting += new FileTansferEvent(scp_OnConnecting);
                scp.OnStart += new FileTansferEvent(scp_OnProgress);
                scp.OnEnd += new FileTansferEvent(scp_OnEnd);
                scp.OnProgress += new FileTansferEvent(scp_OnProgress);
    
                try
                {
                    scp.To(fileName, host, remoteFile, user, password);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
    

    I can successfully connect, send and receive files using CoreFTP. Thus, the issue is not with the server. When I run the above code, the process seems to stop at the scp.To method. It just hangs indefinitely.

    Anyone know what might my problem be? Maybe it has something to do with adding the key to the a SSH Cache? If so, how would I go about this?

    EDIT: I inspected the packets using wireshark and discovered that my computer is not executing the Diffie-Hellman Key Exchange Init. This must be the issue.

    EDIT: I ended up using the following code. Note, the StrictHostKeyChecking was turned off to make things easier.

                JSch jsch = new JSch();
                jsch.setKnownHosts(host);
    
                Session session = jsch.getSession(user, host, 22);
                session.setPassword(password);
    
                System.Collections.Hashtable hashConfig = new System.Collections.Hashtable();
                hashConfig.Add("StrictHostKeyChecking", "no");
                session.setConfig(hashConfig);
    
                try
                {
                    session.connect();
    
                    Channel channel = session.openChannel("sftp");
                    channel.connect();
                    ChannelSftp c = (ChannelSftp)channel;
    
                    c.put(fileName, remoteFile);
    
                    c.exit();            
                }
                catch (Exception e)
                {
                    throw e;
                }
    

    Thanks.

  • nRk
    nRk almost 14 years
    Hi, How can I use private & public keys which generated by "PuTTY Key Generator" to connect to openSSH sftp server with Tamir.SharpSHH clinet?. Thanks.
  • nRk
    nRk almost 14 years
    i converted private key file PuttyKey format to OpenSSH format using "Puttykeygen.exe" Conversions->Export OpenSSH Key. Thanks