Thank you K. Tsang for your suggestion but need your clarification on whether JSCH FTP can access files via URL HTTP protocol. My experience with FTP in
general is that it requires user authentication compared to URLConnection / ImageIO.
It would be excellent if you could provide / refer to an example which uses JSCH to download URL document.
My Google searches on JSCH have not found sufficient example on how it is use in this context. On the other hand, there are plenty of CURL / libCurl, JavacURL
material but not sure which is a better tool to use.
I am only interested in downloading a few advertisement images (small size JPEG) but needs to validate their existence other additional related files not published,
to avoid bringing down the primary Java application altogether.
Jack Bush wrote: Thank you K. Tsang for your suggestion but need your clarification on whether JSCH FTP can access files via URL HTTP protocol
There's no such thing as "URL HTTP protocol".
A URL is a way of locating a resource. It has nothing to do with the protocol for retrieving that resource. We can have an FTP URL or an HTTP URL or a file URL, etc.
To transfer the file, you can use the FTP protocol, or you can use the HTTP protocol, or you can use some other protocol. However, to see if the file exists, you will not, in the general case, be able to use the HTTP protocol. It's possible in some cases, and if you control the server, you may be able to configure it to allow you to find out, but it's not something you should generally rely on.
And there's not usually a reason to check if it exists before attempting a download. Just try the download, and if it fails, handle the failure. You'll have to do that anyway even if "exists" returns true. If you're lucky, the failure will include an indication of whether it was because the file doesn't exist or for some other reason.
Joined: Oct 20, 2006
Thanks Jeff for your clarification, I recognise the differences between FTP URL and HTTP URL and have tried converting the existing HTTP URL http://images.abc.com/img/2012102/15509/2010035044_1_PM.JPG to ftp://images.abc.com/img/2012102/15509/2010035044_1_PM.JPG in order to download it using FTP but failed to find it. My challenge is either to convert the existing HTTP URL to FTP one, or to
use the right download tool / libraries that could take the HTTP URL. Also not sure how to handle a download failure either. Looks like there are a lot of missing puzzles that needs to be
enlightened on since I am new to download in Java, a little example or reference material goes a long way.
That will only be possible in certain special circumstances. To wit:
1. There will have to be an FTP server running serving that provides access to the resources you want. Are you certain that there will be one?
2. There will have to be a known voncertion between the HTTP location and the FTP one. There's no reason to assume that the FTP service will be rooted at the same file system location on the server as the HTTP server is, and there's no way in general to find out where either one is relative to the remote file system or to each other. So you'll have to know ahead of time how the FTP server and HTTP server have been configured.
use the right download tool / libraries that could take the HTTP URL.
You can't just assume that there exists a corresponding FTP path to any given HTTP resource. Unless you know that an FTP server is running and know how it's configured, you'll have to use HTTP. There are HTTP clients out there. Apache has a decent one I believe. Even the classes provided in the core API are okay for simple stuff.
Also not sure how to handle a download failure either.
At the moment that's not a Java question. It's a requirements question. You're basic options are 1) Try again, and 2) Throw an exception.
a little example or reference material goes a long way.
I'm sure a google search for something like java http download example will turn up something useful.