我有一个与FTP服务器连接的问题。我有一个应用程序,它必须从文件中读取数据。我有在本地磁盘上搜索文件的代码,但我必须更改它,因为我的所有数据都在FTP服务器上。此时,我使用:
FileChannel fc = new FileInputStream("C:/Data/" + nameFile)
.getChannel();其中nameFile是命名我的文件。我创建了一个通道,从本地磁盘加载文件中的数据。我可以更改我可以在FTP服务器上搜索文件代码吗?
发布于 2012-01-02 23:30:55
我不完全理解你的帖子,但听起来你在寻找一些代码来检查文件是否存在于远程FTP服务器上,对吗?如果是这样,那么您将需要执行以下操作:
我已经使用http://www.jscape.com/products/components/java/secure-ftp-factory/的Secure FTP Factory成功地做到了这一点
示例代码
Ftp ftp = new Ftp(hostname,username,pass);
ftp.connect();
// get directory listing
Enumeration listing = ftp.getDirListing();
// enumerate thru listing
while(listing.hasMoreElements()) {
FtpFile file = (FtpFile)listing.nextElement();
// check to see if filename matches
System.out.println("Filename: " + file.getFilename());
}发布于 2012-01-02 02:58:33
您必须使用FTP协议的命令,最好使用FTP库。Apache Commons的FTPClient相当不错。
发布于 2012-01-02 02:59:42
为什么不使用像ftp4j这样的东西呢?http://www.sauronsoftware.it/projects/ftp4j/
https://stackoverflow.com/questions/8694802
复制相似问题