1

我正在尝试使用代码在 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");
    }

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

4

0 回答 0