/** * @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; } 断点调试的时候,他会卡在client.connect(server, port)的地方不动,在过一会就报 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) 请教一下怎么回事啊,我用FTP工具可以正常使用FTP服务器上传东西 |
|
40分 |
会不会是权限不足。
|
权限不足不会是这个错误吧? |
|
解决了, FTPSClient在实例化时如果你有SSL应该加TRUE
|
|
client.connect(server, port); 参数怎么传进来的 |
|
楼主大人,FTPSClient在实例化时如果你有SSL应该加TRUE ???怎么加啊
|