久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

URLConnection FTP 列表文件

URLConnection FTP list files(URLConnection FTP 列表文件)
本文介紹了URLConnection FTP 列表文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

URL url =  new URL("ftp://user:pass@ftp.example.com/thefolder/");
URLConnection connection = url.openConnection();
...
// List files in folder...

使用類似上面的方法,我想知道如何獲取文件夾thefolder"中的文件列表?

Using something like the above, I was wondering how I could grab a list of files within folder 'thefolder'?

從這個原始問題開始,我整理了這個簡單的 FTP 連接,它一切正常,看起來不錯.它可以看到/live/conf/位置的所有文件,并將它們全部復制到本地/conf/位置.

Following on from this original question, I have put together this simple FTP connection which is all working and looking good. It can see all files in the /live/conf/ location and copies them all to the local /conf/ location.

唯一的問題是,它正在復制文件但沒有內容.它們都是 0KB 并且是空的.

The only issue is, it is copying the files but there's no content.They are all 0KB and empty.

任何人都可以看到任何明顯的復制文件名而不是文件內容的內容嗎?

Can anyone see anything obvious that'd be copying the filename but not file content?

try {
    FTPClient ftp = new FTPClient();
    ftp.connect("000.000.000.000");
    ftp.login("USER", "PASSWORD");
    ftp.enterLocalPassiveMode();
    ftp.setFileType(FTP.BINARY_FILE_TYPE);

    FTPFile[] files = ftp.listFiles("/live/conf/");
    for (int i=0; i < files.length; i++) {
        if (files[i].getName().contains(".csv")) {

            String remoteFile1 = files[i].getName();
            File downloadFile1 = new File("/var/local/import/conf/"+files[i].getName());
            OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
            ftp.retrieveFile(remoteFile1, outputStream1);
            outputStream1.close();                  

        }
    }
    ftp.disconnect();
} catch (SocketException ex) {
    ex.printStackTrace();
} catch (IOException ex) {
    ex.printStackTrace();
}   

推薦答案

Java SE URLConnection 不適合從 FTP 主機檢索文件列表的工作.至于 FTP,它基本上只支持 FTP 的 getput 命令(檢索或上傳文件).它不支持您基本上正在尋找的 FTP ls 命令(列出文件),更不用說其他許多命令了.

The Java SE URLConnection is insuitable for the job of retrieving a list of files from a FTP host. As to FTP, it basically only supports the FTP get or put commands (retrieve or upload file). It does not support the FTP ls command (list files) which you're basically looking for, let alone many others.

您需要尋找支持 FTP ls 命令(以及更多)的第 3 方庫.一個常用的是 Apache Commons Net FtpClient.在其 javadoc 是演示了如何發出 ls:

You need to look for 3rd party libraries supporting the FTP ls command (and many more). A commonly used one is the Apache Commons Net FtpClient. In its javadoc is demonstrated how to issue a ls:

FTPClient f = new FTPClient();
f.connect(server);
f.login(username, password);
FTPFile[] files = f.listFiles(directory);

這篇關于URLConnection FTP 列表文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产精品久久久久久久粉嫩 | 久久99精品久久久 | 狠狠干网站 | 久久精选| 中文字幕日韩欧美一区二区三区 | 99精品欧美一区二区三区综合在线 | 国产欧美一区二区三区久久手机版 | 欧美精品一区二区三区一线天视频 | 天堂一区 | 久久99精品久久久久久 | 天天天天操 | 国产黄色网址在线观看 | 成人av在线播放 | 亚洲一区二区三区在线 | 国产高清久久 | 国产乱码精品一品二品 | 欧美高清hd | 婷婷99 | 亚洲精品久久区二区三区蜜桃臀 | 国产视频一视频二 | 羞羞的视频免费看 | 国产午夜精品久久久久 | 亚洲一区二区精品视频 | 激情五月婷婷 | 亚洲最大看片网站 | 91秦先生艺校小琴 | 中文字幕一区二区三区四区五区 | 欧美久久一级 | 天天干天天玩天天操 | 91精品福利 | 一区在线视频 | 亚洲第1页 | 色网在线播放 | 在线欧美一区 | 欧美黄视频 | 不卡视频在线 | 精品国产一区二区三区久久狼黑人 | 日韩精品视频在线免费观看 | 中文字幕一区二区三区四区 | 在线欧美一区 | 激情av网站 |