Take the 2-minute tour ×

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);

                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();

            Session session = jsch.getSession(user, host, 22);

            System.Collections.Hashtable hashConfig = new System.Collections.Hashtable();
            hashConfig.Add("StrictHostKeyChecking", "no");


                Channel channel = session.openChannel("sftp");
                ChannelSftp c = (ChannelSftp)channel;

                c.put(fileName, remoteFile);

            catch (Exception e)
                throw e;


share|improve this question
Have you tried watching the traffic with WireShark? it would be interesting to see if the request ever even made it out. –  ryber Oct 16 '09 at 17:33
try making the connection manually with something like pscp (from the makers of PuTTY) and see what happens. –  Malfist Oct 16 '09 at 17:39
@ryber, I inspected packets and discovered that it stops right before the Diffie-Hellman Key Exchange Init.. –  jinsungy Oct 16 '09 at 18:03
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
i went away from using SCP. thanks. –  jinsungy Oct 22 '09 at 16:19
add comment

I use Tamir.SharpSSH - latest version

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

Quick Sample here: - Server IP

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

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


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

Let me know if you have any issues.

share|improve this answer
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 May 11 '10 at 13:44
i converted private key file PuttyKey format to OpenSSH format using "Puttykeygen.exe" Conversions->Export OpenSSH Key. Thanks –  nRk May 12 '10 at 12:02
add comment

Your Answer


