Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3k views
in Java FTP by (160 points)
Hi,

When I transfer files from a remote file system I sometimes do not have permission to write to the local file system. This causes the FTPClient method get(java.lang.String localPath, java.lang.String remoteFile) to throw an IOException. I catch the exception but the next ftp command that I try and execute just times out and returns with the message "Read timed out". I am able to disconnect and then reconnect and everything works fine but this is not a good solution as there is a large amount of code and it has to be easily maintained. Is there another way to fix the connection when the exception is thrown or do you have to handle the exception in a specific way?

Any help will be greatly appreciated. If my code is required in order to solve this problem please let me know and I will post it.

Thanks,
Peter

2 Answers

0 votes
by (162k points)
A check is performed to see if the file is writable before doing much else - in this case you'll get an FTPException saying the file isn't writable, and you can catch this and all should be fine. However this check is only done if the file exists.

If the file doesn't exist, I suppose we could do the same thing on the directory, but this is notoriously unreliable in Java. The best test is to create the file and write to it, which is what the code does.

Your server doesn't seem to like the transfer being terminated. Post the debug file if you'd like us to take a look.

Probably the easiest thing to do is just to create the file first and try writing to it yourself, before attempting the transfer.
0 votes
by (160 points)
Thanks so much for your help. I created the file and checked if it was writable before the transfer and that works perfectly.

You saved a lot of my hair being pulled out.

Cheers,
Peter

Categories

...