Discuss (FTP) and (SFTP, FTPS and SCP), our Java file transfer clients.
no avatar
User

dhan

Posts

4

Joined

Sat Jan 05, 2008 6:29 am

Check the pathname is a file or directory?

by dhan » Sat Jan 05, 2008 6:40 am

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);
no avatar
User

EDT Support

Posts

905

Joined

Mon Apr 26, 2004 3:03 pm

by EDT Support » Sat Jan 05, 2008 11:14 am

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)
no avatar
User

val360

Posts

9

Joined

Wed Mar 17, 2010 12:28 pm

Location

Atlanta, GA

by val360 » Wed Mar 17, 2010 2:43 pm

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?
no avatar
User

EDT Support

Posts

905

Joined

Mon Apr 26, 2004 3:03 pm

by EDT Support » Wed Mar 17, 2010 3:32 pm

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)
no avatar
User

support2

Posts

3987

Joined

Tue May 18, 2004 8:30 am

by support2 » Wed Mar 17, 2010 5:22 pm

You could also list the directory - the FTPFile object will tell you if it is a directory.

Who is online

Users browsing this forum: Google [Bot] and 113 guests

Powered by phpBB ® | phpBB3 Style by KomiDesign
cron