日期:2014-05-19  浏览次数:20627 次

请教JAVA FTP上传的一个问题
Java code

 /**
     * @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)的地方不动,在过一会就报
Java code

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服务器上传东西

------解决方案--------------------
会不会是权限不足。