Meaningless Drivel is fun!*
The moose likes Sockets and Internet Protocols and the fly likes Downloading from FTP Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Downloading from FTP Server" Watch "Downloading from FTP Server" New topic
Author

Downloading from FTP Server

Krutika Ravi
Greenhorn

Joined: Feb 11, 2010
Posts: 23
Hi,

I have been trying to download a file from the ftp server, barring it none of the other files or the directories have been assigned any access rights. Now when I try and download this file from the browser with the filepath appended to the url I face no problem. Whereas when I try to download it via the Java code I face access related exception. The reason I understand is that since the code makes connection with the server first and then checks for directory rights(which are false in this case) I'm unable to download the file.
Could anyone help me understand what procedure the browser might be making use that it is allowed to download the file even though the parent directories of this file have no rights? Or if anybody can suggest an alternative approach then nothing like it.


I have attempted to download th file by making use of the following approach:

Approach 1 :


Approach 2:



Thanks a lot.
Krutika
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

Krutika Ravi wrote:




Your URL is incorrect. See the example here. It would be a good idea to show us the exception you are getting as well. Is it the same with both approaches?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Krutika Ravi
Greenhorn

Joined: Feb 11, 2010
Posts: 23
Hie Joe,

The slash i missed out was a typo and I have tried the url with the type specification i.e type=d and without it (i.e the actual password embedded url) and none work with both approach. Surprisingly when I try and download the file by making use of the same url I face no hassles i face in downloading the file.

URL : URL redacted, though it looks correct JCE

The exception I encounter is:
java.io.FileNotFoundException:URL REDACTED/ftmyersbeach_data.zip
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:441)
Krutika Ravi
Greenhorn

Joined: Feb 11, 2010
Posts: 23
With approach two I face the following exception:

Here1:ftp://URL REDACTED/
java.net.UnknownHostException: ftp:/URL REDACTED/
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at org.apache.commons.net.DefaultSocketFactory.createSocket(DefaultSocketFactory.java:52)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:161)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:249)
at ftpdownloaddemo.FtpDownloadDemo.main(FtpDownloadDemo.java:33)
Exception in thread "main" java.lang.NullPointerException
at org.apache.commons.net.telnet.TelnetClient.disconnect(TelnetClient.java:124)
at org.apache.commons.net.ftp.FTP.disconnect(FTP.java:361)
at org.apache.commons.net.ftp.FTPClient.disconnect(FTPClient.java:562)
at ftpdownloaddemo.FtpDownloadDemo.main(FtpDownloadDemo.java:84)
Java Result: 1


Thanks..
Krutika
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

There's something weird about that FTP server. If I log in using your credentials, I can't CD to the download directory:



I don't know why it works with a browser.
By the way, it looks like your URL above goes to live data. I am going to remove it so you aren't exposing your data.
As for why you are getting a UnknownHostException: with approach #2, I can't tell you since you aren't showing us the URL you are using.
You should probably set up a test environment with bogus data so you can do realistic testing without exposing real data.
Krutika Ravi
Greenhorn

Joined: Feb 11, 2010
Posts: 23
Thats because, barring the file ftmyersbeach_data.zip no access rights have been provided be it directories or files. Its just this sole file.

Yes thats why I was avoiding sharing it in the first place..

Following is the second approach with the URL specified again (you can remove it, just wanted to provide clarity if that could help):




Could anybody help me... I really don't get what is the browser's approach and how is it any different from mine..
Or any other workaround - something similar to calling this url via a browser maybe?

Regards,
Kru
 
jQuery in Action, 2nd edition
 
subject: Downloading from FTP Server