请教JAVA FTP上传的一个问题

J2EE 码拜 9年前 (2015-04-09) 997次浏览 0个评论
 
 /**
     * @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服务器上传东西

请教JAVA FTP上传的一个问题
40分
会不会是权限不足。
请教JAVA FTP上传的一个问题
引用 1 楼  的回复:

会不会是权限不足。

权限不足不会是这个错误吧?

请教JAVA FTP上传的一个问题
解决了, FTPSClient在实例化时如果你有SSL应该加TRUE
请教JAVA FTP上传的一个问题
client.connect(server, port);

参数怎么传进来的

请教JAVA FTP上传的一个问题
楼主大人,FTPSClient在实例化时如果你有SSL应该加TRUE ???怎么加啊

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明请教JAVA FTP上传的一个问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!