2017-10-14 138 views
0

我想將文件從ftp服務器傳輸到hdfs。這個方法我試過:FTP TO HDFS,演示代碼如下:爲什麼Hadoop FTPFileSystem.listStatus(路徑路徑)不起作用?

Configuration conf = new Configuration(); 
    FTPFileSystem ftpfs = new FTPFileSystem(); 
    ftpfs.setConf(conf); 
    ftpfs.initialize(new URI(ftpConnectStr), conf); 

    Path homeDirectory = ftpfs.getHomeDirectory(); 
    System.out.println(homeDirectory.toString()); 

    FileStatus[] fileStatuses = ftpfs.listStatus(new Path("/")); 
    for(FileStatus fileStatus : fileStatuses){ 
     System.out.println(fileStatuses.length); 
     System.out.println(fileStatus.toString()); 
    } 

    boolean test = ftpfs.mkdirs(new Path("test")); 
    System.out.println(test); 

ftpfs.listStatus(new Path("/"))不起作用,它說明不了什麼,但FTP服務器有兩個目錄和ftpfs.mkdirs(new Path("test"))做工精細,運行結果如下方案:

enter image description here

和FTP服務器dirctory如下:

enter image description here

我在谷歌搜索,但找到一些信息。我不知道爲什麼。如果你能幫助我,我將非常感謝,謝謝

+1

@MartinPrikryl https://hadoop.apache.org/docs/r2.4.1/api/org/apache/hadoop/fs/ftp/FTPFileSystem.html#listStatus(org.apache.hadoop.fs。路徑) – Smittey

+0

你能告訴我們一個Hadoop日誌文件嗎? –

+0

什麼是ftp文件夾中的文件的文件權限?運行你的軟件的過程能看到它們嗎?它是否具有正確的權限?通過將一個虛擬文件放在那裏與chmod 777或其他東西來確認 – Smittey

回答

0

最後,我發現問題在哪裏;在FTP服務器中,數據轉發模式設置爲被動模式。

enter image description here

然後我debuged FTPFileSystem的源代碼,和我發現它沒有設置FTP被動模式;

enter image description here

所以,我修改FTPFileSystem的相關代碼如下:

enter image description here

重新運行該程序:

enter image description here

,它工作正常:

enter image description here