wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Download file from FTP using java client 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 "Download file from FTP using java client" Watch "Download file from FTP using java client" New topic
Author

Download file from FTP using java client

gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
Hi All,

is that possible to download a file from FTP using java client. i have tried access servlet via java client. i am not sure about FTP site, any insight on this highly appreciated!

Thanks
Gopi
gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
this doc helped me to connect to ftp and download the files.
http://www.nsftools.com/tips/JavaFtp.htm

but not sure how to browser ftp site. any insight on this appreciated!

Thanks
Gopi
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41603
    
  55
The Jakarta Commons Net project includes an ftp client library, which makes it easy to include ftp capabilities into your application.


Ping & DNS - my free Android networking tools app
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

You can do basic FTP using the Standard API:


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
gopinathang nathan
Ranch Hand

Joined: Oct 28, 2006
Posts: 41
Hi Joe and Ulf, as you mentioned, i could directly refer the file and download. Is it possible to log into ftp site and based on the folder name provided, can i browse and get the files in that folder?

For excample
ftp://user ass@ftpsite.com/gopi/a.txt

i will log in using the URL - ftp://user ass@ftpsite.com. will be possible to browse folders under the root and get 'a.txt'?

Thanks again
[ November 14, 2006: Message edited by: gopinathang nathan ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

If you use the Jakarta Commons Net package Ulf mentioned, there's methods in the FTP client object to list the contents of a directory.
With the URL-based method, you simply request the directory rather than a particular file.
The convenient thing about the Net package is that they do the parsing of the directory information for you. With the URL-based method you get a text listing of the directory and you have to parse out the file names.
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
I Can't get jakarta commons to work true proxy and nat

// Mathias


SCJP1.4
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

Did you read the Commons Net FAQ?

Q: Does FTPClient support FTP connections through an FTP proxy server?

A: Paul Buchanan answers this question here: [WWW] http://marc.theaimsgroup.com/?l=jakarta-commons-user&m=107877944806547&w=2

The summary is:

Since the Net project uses java.net.Socket under the covers, you have to set up the Socket settings. If the proxy you are using is a SOCKS4 or SOCKS5 proxy, you can set the following System Properties:

System.getProperties().put( "socksProxyPort", "1080");
System.getProperties().put( "socksProxyHost" ,"proxy.host.address");

From what I can tell, 1080 is the default port for SOCKS proxies. The following site documents many of the networking System Properties available:

http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Thanks!

I have read this link but our firewall, nat etc is on a sun solaris with an proxy server that does not support socks proxy. Only http and ftp
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Download file from FTP using java client