求助:FTPClient.connect的时候异常[比较急, 要分我可以+]
String result = "上传处不成功";
if(list != null){
FTPClient ftpClient = new FTPClient();
FileInputStream fis = null;
int reply = 0;
try {
ftpClient.connect(loginInfo.getIP());
ftpClient.login(loginInfo.getAccount(), loginInfo.getPassword());
reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
System.out.println("FTP服务器 拒绝连接");
log.info("FTP服务器 拒绝连接");
return "FTP服务器 拒绝连接";
}
String srcFilePath = CircuitExcel(loginInfo.getDestPath(), list, FileName, loginInfo.getExcelPath());
String fileName = FileName.replace('/', '_')+".xls";
File srcFile = new File(srcFilePath + fileName);
fis = new FileInputStream(srcFile);
//设置上传目录
ftpClient.changeWorkingDirectory(loginInfo.getDestPath());
ftpClient.setBufferSize(1024);
ftpClient.setControlEncoding("GBK");
//设置文件类型(二进制)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile(FileName+".xls", fis); //--生成EXCEL文件
result = "上传处成功";
} catch (IOException e) {
result = "FTP客户端出错!";
e.printStackTrace();
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
try {
ftpClient.disconnect();
} catch (IOException e) {
result = "关闭FTP连接发生异常!";
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
}
return result;
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:267)
at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:335)
at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:550)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:163)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:250)
at com.catt.webservice.inBsBillDispatchSysInterface.service.InBsBillDsptSysService.Upload(InBsBillDsptSysService.java:100)
at com.catt.webservice.inBsBillDispatchSysInterface.service.InBsBillDsptSysService.getCircuit(InBsBillDsptSysService.java:50)
at com.catt.webservice.inBsBillDispatchSysInterface.inBsBillDsptSys.getCircuit(inBsBillDsptSys.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:102)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:100)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:176)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:133)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:731)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:524)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
public boolean login(String host, int port, String user, String pwd)
throws Exception {
boolean flag = false;
try {
client.setControlEncoding("GBK");// 设置登陆编码格式
client.setConnectTimeout(60000);// 超时60秒
client.connect(host.trim(), port);// 连接FTP
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
this.close();
throw new Exception("FTP refuse connect");
}
} catch (SocketException e) {
log.error(e);
throw new SocketException("FTP connect timeout");
} catch (IOException e) {
log.error(e);
throw new IOException("hostname/IP error");
}
......}