FTPClient.listNames返回null。 [英] FTPClient.listNames returning null.
本文介绍了FTPClient.listNames返回null。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用org.apache.commons.net.ftp.FTPClient从ftp服务器获取文件列表,但我无法从服务器获取文件列表。
我发布我的代码请告诉我我错过任何一步的地方。
提前付款
public static void main( String [] args){
FTPClient client = new FTPClient ();
尝试 {
client.connect( 192.168.1.9, 5001 );
String [] flist = client.listNames();
for ( String file:flist)
System。出跨度> .println(文件);
} catch (Exception ex){
System。 out .println(ex .getMessage());
}
}
解决方案
import org.apache.commons.net.ftp.FTPClient;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPFile;
public class BasicFTP {
public static void main( String [] args) throws IOException {
FTPClient client = new FTPClient();
client.connect( c64.rulez.org);
client.enterLocalPassiveMode();
client.login( anonymous, );
FTPFile [] files = client.listFiles( / pub);
for (FTPFile file:files){
if (file.getType( )== FTPFile.FILE_TYPE)
System.out.println(file.getName());
}
}
}
并使用commons-net-ftp-2.0.jar
< blockquote>你能尝试下面的代码来获取文件列表
FTPFile [] ftpFiles = client.listFiles();
Hi,
I am trying to get Filelist from ftp server using org.apache.commons.net.ftp.FTPClient but I Can't get File list from server.
I am posting my code please suggest me where I missed any step.
Thanks in Advance
public static void main(String[] args) {
FTPClient client = new FTPClient();
try {
client.connect("192.168.1.9",5001);
String[] flist = client.listNames();
for (String file : flist)
System.out.println(file);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
解决方案
import org.apache.commons.net.ftp.FTPClient; import java.io.IOException; import org.apache.commons.net.ftp.FTPFile; public class BasicFTP { public static void main(String[] args) throws IOException { FTPClient client = new FTPClient(); client.connect("c64.rulez.org"); client.enterLocalPassiveMode(); client.login("anonymous", ""); FTPFile[] files = client.listFiles("/pub"); for (FTPFile file : files) { if (file.getType() == FTPFile.FILE_TYPE) System.out.println(file.getName()); } } }
and use commons-net-ftp-2.0.jar
Can you try below code to get list of files
FTPFile[] ftpFiles = client.listFiles();
这篇关于FTPClient.listNames返回null。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文