Jsch error - failed to send channel request

Deadly 提交于 2019-11-27 23:50:38

问题


I am trying to connect to a SFTP remote server using JSCH library version 0.1.49. Every time I run the program I receive the following error :

Initializing...
Connection to SFTP server is successfully
com.jcraft.jsch.JSchException: Unable to connect to SFTP server.com.jcraft.jsch.JSchException: failed to send channel request
at shell.MainClass.JschConnect(MainClass.java:95)
at shell.MainClass.main(MainClass.java:30)

line 30 is : sftpChannel.connect() from the code below :

    System.out.println("Initializing...");
    JSch jsch = new JSch();

    Session session = null;
    try {   
        session = jsch.getSession(ProjectConstants.rmUsername,ProjectConstants.rmHost, 22);
        session.setPassword(ProjectConstants.rmPassword);

        java.util.Properties config = new java.util.Properties(); 
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);

        session.connect();
        if (session.isConnected() == true) {
            System.out.println("Connection to SFTP server is successfully");
        }

        ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
        try {
            sftpChannel.connect();
        } catch (Exception e) {
            throw new JSchException("Unable to connect to SFTP server. "
                    + e.toString());
        }

the credentials I am using are correct ( it connects through FileZilla using the same data ), and I also disabled the proxy for that server ( either way I get the same error with or without proxy )

If anyone could help me I would greatly appreciate it as I am stuck with this error for about a week now ...

Thank you.


回答1:


Check if SFTP server is started and running.

I had encountered the same issue - I was not able to open SFTP channel to my server, but I could connect with WinSCP. It took me some time to notice that WinSCP would fallback to SCP hence confusing me. Starting the server solved this issue.




回答2:


Check Subsystem sftp /usr/lib/openssh/sftp-server in /etc/ssh/sshd_config




回答3:


In /etc/ssh/sshd_config I changed:

Subsystem sftp /usr/lib/openssh/sftp-server 

to:

Subsystem sftp internal-sftp 

It helps.



来源:https://stackoverflow.com/questions/14769164/jsch-error-failed-to-send-channel-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!