File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Re:FTP query 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 "Re:FTP query" Watch "Re:FTP query" New topic

Re:FTP query

sunil kumre
Ranch Hand

Joined: Dec 23, 2000
Posts: 64
I'm using a frame to display a button which when clicked should
ask for downloading a file from a server on the client side.

My code looks like this---
// To open socket.
Socket clientsocket =new Socket("",21);
DataOutputStream outbound =new DataOutputStream(clientsocket.getOutputStream());
BufferedReader inbound =new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
outbound.writeBytes("GET /CyberSync_2000.exe /FTP\r\n\r\n");
System.out.println("ftp reguest sever");

---but it is not giving the desired results.
can someone help?

thanks in advance.

[This message has been edited by sunil kumre (edited March 14, 2001).]
maateen ashraf
Ranch Hand

Joined: Jan 08, 2001
Posts: 122
would u tell me what exceptions it throws ....
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
How exactly is it not working? Does the site require a login with username and password? Can you be more specific about your problem?
sunil kumre
Ranch Hand

Joined: Dec 23, 2000
Posts: 64
Hi maateen,
It's giving connection refused: No further information..

I'm also tried for FTP servlet..
But not get How to write FTP servlet???
Do you have any Idea about FTP servlet???
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
Hi sunil
You say that is displayed, but there is NO class named or in the package.
The only exceptions in package are:-
BindException, ConnectException, MalformedURLException, NoRouteToHostException, ProtocolException, SocketException, UnknownHostException, UnknownServiceException
So which exactly is the exception thrown? Solving the problem without specific information is difficult.
Also, if your ftp server-site requires a username, password, then the first command that should be sent over the socket is a login command supplying the username and password. That may be the reason why GET causes connection refused message.
You can also use URL or URLConnection class to download from the ftp site. The code is much simpler:-
URL url=new URL(protocol:resource);
InputStream uin=url.openStream();
If the site requires username and password then do as follows:-
URL url=new URL("ftp://username");

[This message has been edited by Rahul Rathore (edited March 15, 2001).]
I agree. Here's the link:
subject: Re:FTP query
It's not a secret anymore!