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