• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Downloading from FTP Server

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Krutika Ravi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic