Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.5k views
in Java FTP by
Usually ftpClient.dirDetails(aRemoteDirectory) should return FTPFile[] but sometimes when aRemoteDirectory doesn't exist I get

com.enterprisedt.net.ftp.FTPException: List command failed

I would like to this instead

try {
if (ftpClient.dirExists(aRemoteDirectory)) {
RemoteFiles = ftpClient.dirDetails(aRemoteDirectory);
} else {
// aRemoteDirectory doesn't exist. skip this.
continue;
}
} catch(FTPException e) {
//networking error. could possibly try listing command again
...
}

I don't want an FTPException be thrown when the remote directory doesn't exist.

I'd like to be able to tell if dirDetails() fails whether the directory doesn't exist or it is some other transient problem.

Same thing here when I try to delete a non existent file.

try {
ftpClient.delete(aFile);
} catch(FTPException e) {
// is this because the file doesn't exist?
// or is it because there's a network problem while issuing DELE command?
}

The FTPException is too generic, IMHO. Thanks very much. Have to tell l like your work.

4 Answers

0 votes
by (162k points)
FTPException is thrown when the server reports an error with the command that it has been sent.

Transient network errors will result in an IOException, so you should be able to discriminate by catching IOException and retrying.

Usually ftpClient.dirDetails(aRemoteDirectory) should return FTPFile[] but sometimes when aRemoteDirectory doesn't exist I get

com.enterprisedt.net.ftp.FTPException: List command failed

I would like to this instead

try {
if (ftpClient.dirExists(aRemoteDirectory)) {
RemoteFiles = ftpClient.dirDetails(aRemoteDirectory);
} else {
// aRemoteDirectory doesn't exist. skip this.
continue;
}
} catch(FTPException e) {
//networking error. could possibly try listing command again
...
}

I don't want an FTPException be thrown when the remote directory doesn't exist.

I'd like to be able to tell if dirDetails() fails whether the directory doesn't exist or it is some other transient problem.

Same thing here when I try to delete a non existent file.

try {
ftpClient.delete(aFile);
} catch(FTPException e) {
// is this because the file doesn't exist?
// or is it because there's a network problem while issuing DELE command?
}

The FTPException is too generic, IMHO. Thanks very much. Have to tell l like your work.
0 votes
by
Thanks for your quick reply.
That doesn't completely eliminate my problem.
Please take a look at the line starting with "11:".

10: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510219/gco06210.11...Done
10: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510219/gco06210.22...Done

11: Creating download list for clients[11]...11: Remote directory /ticket/home/csbknd/java/split/clientBackup/5510220 could not be listed.
com.enterprisedt.net.ftp.FTPException: PASV command failed

12: Creating download list for clients[12]...Done
12: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510221/55102210404.zip...Done
12: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510221/55102210406.zip...Done
12: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510221/55102210408.zip...Done
12: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510221/55102210412.zip...Done

On another occasion

10: Creating download list for clients[10]...Done
11: Creating download list for clients[11]...Done
11: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510220/55102200404.zip...Done
11: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510220/55102200406.zip...Done
11: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510220/55102200408.zip...Done
11: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510220/55102200412.zip...Done
11: Deleting file /ticket/home/csbknd/java/split/clientBackup/5510220/55102200419.zip...Done

So you see the error "PASV command failed" happens randomly.
It happens once out of 587 similar requests.

I also learnt that "List command failed" means "The remote directory doesn't exist."

583: Creating download list for clients[583]...Done
584: Creating download list for clients[584]...Done
585: Creating download list for clients[585]...585: Remote directory /ticket/home/csbknd/java/split/clientBackup/501/ could not be listed.
com.enterprisedt.net.ftp.FTPException: List command failed

I might probably do this.

if (PASV command failed) {
retry;
} else if (List command failed) {
the directory does not exist, move on;
}
But I don't want to hardcode these error messages into my code.

If I can't discriminate between the two cases, I guess I'll have to retry LISTing for say maybe 5 attempts before the code give up and move on to the next item in the array.

Thank you so much for your time.
0 votes
by (162k points)
If you look at FTPException you'll see it also supplies an error code. You could probably use this to discriminate between errors and to retry if required

Thanks for your quick reply.
That doesn't completely eliminate my problem.
So you see the error "PASV command failed" happens randomly.

[snip]

But I don't want to hardcode these error messages into my code.

If I can't discriminate between the two cases, I guess I'll have to retry LISTing for say maybe 5 attempts before the code give up and move on to the next item in the array.

Thank you so much for your time.
0 votes
by
That sounds great. Should fix my problem. Many thanks!

Categories

...