日期:2014-05-19 浏览次数:20627 次
/** * @Title: connect * @Description: 连接FTP客户端 * @param client * 客户端 * @throws IOException * @throws SocketException */ private FTPClient connectServer() throws SocketException, IOException { FTPSClient client = init(); client.connect(server, port); if (!client.login(userName, password)) { client.logout(); client.disconnect(); client = null; return client; } client.enterLocalPassiveMode(); client.setBufferSize(1024); client.setConnectTimeout(10000); client.setFileType(FTPClient.BINARY_FILE_TYPE); client.setControlEncoding("GBK"); client.enterLocalPassiveMode(); SocketFactory factory=null; factory= SSLSocketFactory.getDefault(); client.setSocketFactory(factory); int replyCode = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { close(client); client = null; throw new IOException("服务器连接失败!username:" + userName + " password:" + password); } return client; }
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication. at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:313) at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290) at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:396) at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:796) at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:203) at org.apache.commons.net.SocketClient.connect(SocketClient.java:172) at org.apache.commons.net.SocketClient.connect(SocketClient.java:192) at service.ftp.client.FileClient.connectServer(FileClient.java:78) at service.ftp.client.FileClient.handle(FileClient.java:103) at service.ftp.client.FileClient.main(FileClient.java:142)