FTP被动模式不上传任何东西(Java)

时间:2013-08-07 07:41:59

标签: java ftp

我正在尝试使用代码

在FTP服务器上上传文件
 try {
        FTPClient ftpClient = new FTPClient();
        ftpClient.connect(host);
        int reply = ftpClient.getReplyCode();
        if (FTPReply.isPositiveCompletion(reply)) {
            ftpClient.enterLocalPassiveMode();

            boolean login = ftpClient.login(user, password);
            if (login) {
                File localFile = new File(fileName);
                InputStream inputStream = new FileInputStream(localFile);
                ftpClient.appendFile("/folder/output.txt", inputStream);
            }
        }
    } catch (Exception ioe) {
        ioe.printStackTrace();
        System.out.println("FTP client received network error");
    }

但是,如果删除ftpClient.enterLocalPassiveMode();,它不会在FTP服务器上上传任何内容 行,它上传一个空的output.txt文件。感谢任何有帮助的人。

0 个答案:

没有答案
相关问题