SFTP连接异常 Could not connect to SFTP server. Caused by: com.jcraft.jsch.JSchException: Auth fail
2014-02-20 16:53
796 查看
连接SFTP服务器时总是抛出以下异常,而且自己也在本地测试800多遍了都没有任何问题,就是在Linux平台下出现的
org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "168.22.73.69".
at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:214)
at com.wxcking.admins.util.sftp.SFTPUtil.connectServer(SFTPUtil.java:270)
at com.wxcking.admins.util.sftp.SFTPUtil.<init>(SFTPUtil.java:66)
at com.wxcking.admins.util.SftpConnectUtil.connectSupBankSftp(SftpConnectUtil.java:36)
at com.wxcking.admins.redeem.service.RedemptionBankService.uploadRegulatoryBank(RedemptionBankService.java:285)
at com.wxcking.admins.redeem.service.RedemptionBankService$$FastClassByCGLIB$$864fe42a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:627)
at com.wxcking.admins.redeem.service.RedemptionBankService$$EnhancerByCGLIB$$b98834a5.uploadRegulatoryBank(<generated>)
at com.wxcking.manage.contract.service.adminsRedeemCollectService.processCollect(adminsRedeemCollectService.java:89)
... ...
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:464)
at com.jcraft.jsch.Session.connect(Session.java:158)
at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:210)
... 111 more
这种异常主要是看Caused by后面的 com.jcraft.jsch.JSchException: Auth fail,报的是 Caused by: com.jcraft.jsch.JSchException: Auth fail验证失败。另外,使用FlashFXP等工具连接SFTP时都没有问题,使用Java写的程序连接出现Auth
fail异常。
从网上查询到解决的方法:
第一种说法是配置参数比如用户名和密码等配置错误。
第二说法是在/etc/ssh/sshd_config文件夹的一个配置项PasswordAuthentication 默认为no,“PasswordAuthentication”设置是否允许口令验证,把它改为yes,重启服务就OK了。
如果您在这一步就已经解决好Auth fail异常的话,祝贺您,您太幸运了!
-----------------------------------------
-----------------------------------------
-----------------------------------------
当我把以上方法都试了以后,还是报Auth fail异常,这时要看一下SFTP连接代码了,在连接SFTP代码中加上下面代码,另外再实现一个日志类。
/**
* SFTP工具类
*/
public class SFTPUtil {
/**
* 连接SFTP服务器
* @throws JSchException
* @throws FileSystemException
*/
private void connectServer() throws JSchException, FileSystemException {
if (this.channel != null) {
disconnect();
}
com.jcraft.jsch.Logger logger = new SettleLogger();
JSch.setLogger(logger);
FileSystemOptions fso = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso, "no");
this.session = SftpClientFactory.createConnection(this.ftpHost,
this.ftpPort, this.userName.toCharArray(),
this.password.toCharArray(), fso);
Channel _channel = this.session.openChannel("sftp");
_channel.connect();
this.channel = ((ChannelSftp) _channel);
}
}
实现com.jcraft.jsch.Logger日志,这个日志是jsch本身的日志工具类,和org.apache.log4j.Logger的日志类不一样。
/**
* 日志工具类
*/
public class SettleLogger implements com.jcraft.jsch.Logger {
public boolean isEnabled(int level) {
return true;
}
public void log(int level, String msg) {
System.out.println(msg);
}
}
这样程序的问题就解决了。。。
org.apache.commons.vfs.FileSystemException: Could not connect to SFTP server at "168.22.73.69".
at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:214)
at com.wxcking.admins.util.sftp.SFTPUtil.connectServer(SFTPUtil.java:270)
at com.wxcking.admins.util.sftp.SFTPUtil.<init>(SFTPUtil.java:66)
at com.wxcking.admins.util.SftpConnectUtil.connectSupBankSftp(SftpConnectUtil.java:36)
at com.wxcking.admins.redeem.service.RedemptionBankService.uploadRegulatoryBank(RedemptionBankService.java:285)
at com.wxcking.admins.redeem.service.RedemptionBankService$$FastClassByCGLIB$$864fe42a.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:627)
at com.wxcking.admins.redeem.service.RedemptionBankService$$EnhancerByCGLIB$$b98834a5.uploadRegulatoryBank(<generated>)
at com.wxcking.manage.contract.service.adminsRedeemCollectService.processCollect(adminsRedeemCollectService.java:89)
... ...
Caused by: com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:464)
at com.jcraft.jsch.Session.connect(Session.java:158)
at org.apache.commons.vfs.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:210)
... 111 more
这种异常主要是看Caused by后面的 com.jcraft.jsch.JSchException: Auth fail,报的是 Caused by: com.jcraft.jsch.JSchException: Auth fail验证失败。另外,使用FlashFXP等工具连接SFTP时都没有问题,使用Java写的程序连接出现Auth
fail异常。
从网上查询到解决的方法:
第一种说法是配置参数比如用户名和密码等配置错误。
第二说法是在/etc/ssh/sshd_config文件夹的一个配置项PasswordAuthentication 默认为no,“PasswordAuthentication”设置是否允许口令验证,把它改为yes,重启服务就OK了。
如果您在这一步就已经解决好Auth fail异常的话,祝贺您,您太幸运了!
-----------------------------------------
-----------------------------------------
-----------------------------------------
当我把以上方法都试了以后,还是报Auth fail异常,这时要看一下SFTP连接代码了,在连接SFTP代码中加上下面代码,另外再实现一个日志类。
/**
* SFTP工具类
*/
public class SFTPUtil {
/**
* 连接SFTP服务器
* @throws JSchException
* @throws FileSystemException
*/
private void connectServer() throws JSchException, FileSystemException {
if (this.channel != null) {
disconnect();
}
com.jcraft.jsch.Logger logger = new SettleLogger();
JSch.setLogger(logger);
FileSystemOptions fso = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(fso, "no");
this.session = SftpClientFactory.createConnection(this.ftpHost,
this.ftpPort, this.userName.toCharArray(),
this.password.toCharArray(), fso);
Channel _channel = this.session.openChannel("sftp");
_channel.connect();
this.channel = ((ChannelSftp) _channel);
}
}
实现com.jcraft.jsch.Logger日志,这个日志是jsch本身的日志工具类,和org.apache.log4j.Logger的日志类不一样。
/**
* 日志工具类
*/
public class SettleLogger implements com.jcraft.jsch.Logger {
public boolean isEnabled(int level) {
return true;
}
public void log(int level, String msg) {
System.out.println(msg);
}
}
这样程序的问题就解决了。。。
相关文章推荐
- SFTP连接异常 Could not connect to SFTP server. Connection timed out
- javax.mail.MessagingException: Could not connect to SMTP host: smtp.xx.com, port: 465;
- aSmack连接server异常smack.SmackException$ ConnectionException thrown by XMPPConnection.connect();
- centos中apache连接postgresql提示SQLSTATE[08006] [7] could not connect to server: Permission denied
- 连接Sql2005报的错误:Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 到主机 的 TCP/IP 连接失败
- Eclipse中使用SVN连接Google Code 报could not connect to server错误解决方法
- Caused by: org.hibernate.MappingException: Could not determine type for: com.bjsxt.model.Specialty, at table: Student, for columns: [org.hibernate.map
- android 升级ADT到22后,出现bug: Could not find class,或者Caused by: java.lang.ClassNotFoundException:异常
- 解决:ould not find a getter for porDate in class com.bc.bean.PortalSheet Caused by: org.hibernate.PropertyNotFoundException: Could
- 坑之关于dubbo服务产生异常之:Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side respons
- svn could not connect to the server 不能连接到服务器的解决方法
- 关于使用Java Mail进行邮件发送,抛出Could not connect to SMTP host: xx@xxx.com, port: 25的异常可能
- 关于dubbo服务产生异常之:Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer.
- android 升级ADT到22后,出现bug: Could not find class,或者Caused by: java.lang.ClassNotFoundException:异常
- Dubbo服务启动时Caused by: com.alibaba.dubbo.remoting.RemotingException: Failed to bind NettyServer on /19
- dubbo产生异常之:Caused by: com.alibaba.dubbo.remoting.TimeoutException: Waiting server-side response ti
- PostgreSQL安装后Navicat客户端连接报错:Could not connect to server:Connection refused(0x00002740/10061)
- Host 'xxx.xx.xx-xx.xx.com' is not allowed to connect to this MySQL serverConnection closed by foreig
- Host 'xxx.xx.xx-xx.xx.com' is not allowed to connect to this MySQL serverConnection closed by foreig
- Phoenix 连接hbase 异常:Caused by: java.lang.ClassNotFoundException: org.iq80.snappy.CorruptionException