Reputation: 3031
I have a problem with connection with FTP server. I have a application, which must read data from files. I have code where I searching files at my local disk, but I must change that because I have all data at FTP server. At this time I using:
FileChannel fc = new FileInputStream("C:/Data/" + nameFile)
.getChannel();
where nameFile is name my file. I create channel where I load data from file from local disk. Can I change that code that I can search files at FTP server?
Upvotes: 0
Views: 1551
Reputation: 36
I don't fully understand your post, but it sounds like you are looking for some code to check whether a file exists on the remote FTP server, correct? If so, then you will want to do the following:
Connect to server and authenticate.
Navigate to directory on remote system
Perform a directory listing of remote system
Check to see if any of the files in directory listing match the file you are looing for.
I've done this successfully using Secure FTP Factory at http://www.jscape.com/products/components/java/secure-ftp-factory/
Example Code
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());
}
Upvotes: 2
Reputation: 1716
Why not just use something like ftp4j? http://www.sauronsoftware.it/projects/ftp4j/
Upvotes: 0