第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將文本文件 (txt) 寫入我的 ftp 服務器?

如何將文本文件 (txt) 寫入我的 ftp 服務器?

千萬里不及你 2023-09-27 16:53:13
我怎樣才能做到這一點?誰能幫助我?我嘗試了所有 Apache 插件,但它不起作用!你知道有什么插件可以幫助我編寫txt文件并將它們寫入我的FTP服務器嗎?我的榮幸。(對不起,我的英語一點也不好)
查看完整描述

1 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

首先,你不能直接在FTP上寫文件。您需要將其寫入本地,然后將其存儲在 FTP 上。試試這個,它對我有用。


public static void main(String[] args) {

    String server = "ftp://ftp.dlptest.com/";

    int port = 21;

    String user = "dlpuser@dlptest.com";

    String pass = "fLDScD4Ynth0p4OJ6bW6qCxjh";


    FTPClient ftpClient = new FTPClient();

    try {


        ftpClient.connect(server, port);

        ftpClient.login(user, pass);

        ftpClient.enterLocalPassiveMode();


        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);


        File firstLocalFile = new File("C:/Users/Administrator/Desktop/Book1.xlsx");


        String firstRemoteFile = "Book1.xlsx";

        InputStream inputStream = new FileInputStream(firstLocalFile);


        System.out.println("Start uploading first file");

        boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);

        inputStream.close();

        if (done) {

            System.out.println("The first file is uploaded successfully.");

        }

    } catch (IOException ex) {

        System.out.println("Error: " + ex.getMessage());

        ex.printStackTrace();

    } finally {

        try {

            if (ftpClient.isConnected()) {

                ftpClient.logout();

                ftpClient.disconnect();

            }

        } catch (IOException ex) {

            ex.printStackTrace();

        }

    }


查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 112 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號