問題描述
我正在嘗試列出 ftp 服務器中特定目錄下的所有文件.
I am trying to list all the files under a specific directory in a ftp server.
FTPFile[] subFiles = ftpClient.listFiles("directory");
雖然目錄是有效的,但調用 listFiles 時代碼卡住了,可能是什么原因.?此外,我想提一下,訪問同一 FTP 服務器的單獨 netbeans 項目使用相同的代碼可以正常工作,但是 maven 項目存在問題.請幫忙.
Although the directory is a valid one , but the code gets stuck while calling listFiles , what may be the reason. ? Further i would like to mention that a seperate netbeans project accessing the same FTP server is working fine with the same code , but a maven project is having the problem. please help.
推薦答案
嘗試使用被動模式
.我假設你使用的是最新的 commons net 庫(你沒有寫哪個你正在使用的lib).
Try to use passive mode
. I assume that you are using the newest commons net library (you didn't write which lib you are using).
下一個方法,嘗試更改文件列表布局.公共庫使用自動檢測,但在某些情況下這不起作用.您可以更改(和測試)另一個文件列表布局,如下所示:
Next approach, try to change the file list layout. The commons lib uses auto-detection but in some cases this doesn't work. You can change (and test) another file list layout as followed:
FTPClientConfig configuration = new FTPClientConfig(FTPClientConfig.TEST_YOURSELF);
FTPClient yourClient = FTPClient(...);
client.configure(conf);
這篇關于FTPClient.listFiles 不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!