Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.1k views
in Java FTP by (162k points)
A user writes:

I want to know whether there is a directory in the remote FTP Server or not.
I tried to use FTPCliet.exists method to solve this.
But it throws Exception that "Unable to determine if file ~~ exists."

Maybe, I think that method supports only a file, the real file.
So, I tried it with a remote file, and it was successful.

However, I really wanted is to know the existence of a directory, not a file.
As you know, there is no distinction between a direcotry and a file in UNIX system.

Would please let me know what I should use to solve this?


The answer is that exists() is only intended to test for the existence of a file.

To test for the existence of a directory, you can

1) try changing into that directory - you'll get an exception if it doesn't exist (or if you don't have perms for it)
2) use dirDetails() or listDirectory() (see FileTransferClient) on the parent and examine the listing to see if the directory appears in the listing

7 Answers

0 votes
by (220 points)
Thanks for a kind answere.

Anyway, I want to make a directory in the remote FTP Server
like the following code as File.mkdirs() method in the Java Api.
fClinet.mkdirs("path");

Is there any?
0 votes
by (162k points)
FTPClient.mkdir("dir")
0 votes
by (220 points)
As you know, mkdirs() supports the rucursion
0 votes
by (162k points)
It will depend on the FTP server.

Some may accept ftp.mkdir("abc/efg/hij") where these are all new directories.

Otherwise you will need to mkdir, chdir, mkdir, chdir etc

This might be a useful method for us to add at some point.
0 votes
by (220 points)
Maybe, this FTP server is not that case.

Anyway, I got a lot help from you, sincerely.

I much appreciate to you and your Open source.
0 votes
by (1.3k points)
Will this feature considered to be added?
0 votes
by (162k points)
It's on our to do list.

Categories

...