aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Re:FTP query" Watch "Re:FTP query" New topic
Author

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---
try
{
// To open socket.
Socket clientsocket =new Socket("192.168.0.108",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 sent.....to 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
java.net.exception: 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???
Thanx
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
Hi sunil
You say that java.net.exception is displayed, but there is NO class named java.net.exception or java.net.Exception in the java.net package.
The only exceptions in java.net 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 :password@ftp.yourserver.com/pub/file.txt");

[This message has been edited by Rahul Rathore (edited March 15, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Re:FTP query