今天使用SFTP连接服务器的时候突然报出如下问题
java.lang.RuntimeException: Sftp connect to error
at com.talkweb.mobilezone.publicutilitie.settling.utils.SimpleSftp.connectWithKey(SimpleSftp.java:102) ~[classes/:na]
at com.talkweb.mobilezone.publicutilitie.xinaorq.XarqTaskImpl.loadFileFromSFTP(XarqTaskImpl.java:512) [classes/:na]
at com.talkweb.mobilezone.publicutilitie.xinaorq.XarqTaskImpl.getFileUseFtp(XarqTaskImpl.java:182) [classes/:na]
at com.talkweb.mobilezone.publicutilitie.xinaorq.XarqTaskImpl.execWithParams(XarqTaskImpl.java:124) [classes/:na]
at com.talkweb.mobilezone.publicutilitie.commons.AbstractPubTaskJob.pubTask(AbstractPubTaskJob.java:34) [classes/:na]
at com.talkweb.mobilezone.publicutilitie.xinaorq.XarqTaskImpl.execJob(XarqTaskImpl.java:605) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_27]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_27]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_27]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_27]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) [spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:77) [spring-context-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) [spring-aop-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at $Proxy49.execJob(Unknown Source) [na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_27]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_27]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_27]
at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_27]
at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:306) [hessian-4.0.7.jar:na]
at com.caucho.hessian.server.HessianSkeleton.invoke(HessianSkeleton.java:221) [hessian-4.0.7.jar:na]
at org.springframework.remoting.caucho.HessianExporter.doInvoke(HessianExporter.java:198) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.remoting.caucho.HessianExporter.invoke(HessianExporter.java:118) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.remoting.caucho.HessianServiceExporter.handleRequest(HessianServiceExporter.java:66) [spring-web-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49) [spring-webmvc-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788) [spring-webmvc-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717) [spring-webmvc-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) [spring-webmvc-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) [spring-webmvc-3.0.4.RELEASE.jar:3.0.4.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) [servlet-api.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [catalina.jar:7.0.70]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.70]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) [catalina.jar:7.0.70]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [catalina.jar:7.0.70]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) [catalina.jar:7.0.70]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) [catalina.jar:7.0.70]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:7.0.70]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) [catalina.jar:7.0.70]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [catalina.jar:7.0.70]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) [catalina.jar:7.0.70]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) [tomcat-coyote.jar:7.0.70]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) [tomcat-coyote.jar:7.0.70]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1756) [tomcat-coyote.jar:7.0.70]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1715) [tomcat-coyote.jar:7.0.70]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_27]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_27]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-coyote.jar:7.0.70]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_27]
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read
at com.jcraft.jsch.Session.connect(Session.java:565) ~[jsch-0.1.54.jar:na]
at com.jcraft.jsch.Session.connect(Session.java:183) ~[jsch-0.1.54.jar:na]
at com.talkweb.mobilezone.publicutilitie.settling.utils.SimpleSftp.connectWithKey(SimpleSftp.java:93) ~[classes/:na]
... 50 common frames omitted
解决方案
1、修改服务器/etc/ssh/sshd_config配置文件,添加如下代码:
KexAlgorithms +diffie-hellman-group1-sha1
2.修改sftp的代码
JSch jsch = new JSch(); sch.getSession(username, host, port); sshSession = jsch.getSession(username, host, port);
添加如下参数
session.setConfig("kex",“diffie-hellman-group1-sha1”);