Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
6k views
in Java FTP by (220 points)
Is there a way/method to check the given remote pathname is a directory or a file?

For example,
FtpClient ftp = new FTPClient();
boolean directory = ftp.isDirectory(remote pathname);

4 Answers

0 votes
by (51.6k points)
There's no method for doing that, but you could just try to change into it. If you can then it's a directory. If you can't then it's either because the directory doesn't exist or because you don't have permission to access it. In the latter case you can check the reply code to distinguish between non-existence and lack of permission.

- Hans (EnterpriseDT)
0 votes
by (400 points)
using chdir and catching the exception doesn't seem like a reliable way to check if the issue is permission or if the directory does not exist. Doesn't the specific message depend on the ftp server, if so there are many possibilities to check for. Are there any plans to include exists method for directories?
0 votes
by (51.6k points)
The good news: In the current production release, there's a method called DirectoryExists in FTPConnection, but it's internal. If you change it to public and recompile the project then you'll be able to use it. It will be public in the next release.

The bad news: All it does is try to change into the directory, which is the best generic solution that we know of. We have a policy of not including server-specific workarounds, so that's the best we can do.

- Hans (EnterpriseDT)
0 votes
by (162k points)
You could also list the directory - the FTPFile object will tell you if it is a directory.

Categories

...