Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read a file from remote System

 
somenath chatterjee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I want to read a file from remote computer, verifying with user authentication using java.If any one done this kind of code please help me..
Thank you.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDBC wouldn't help you with that. Let's move this somewhere more appropriate.
 
Norm Radder
Ranch Hand
Posts: 894
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to do this. Depends on what software in running on the server and on the client. Perhaps you could explain about that.
On the server what services such as JSP or CGI to handle the verification.
On the client, would there be a browser to read an HTML page and send <Form data to the server?

Or do you intend to write the both sides from scratch?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15288
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll first need to decide on what network protocol you're going to use to talk between your computer and the server. If you'd use FTP for example, you'd need to set up an FTP service on the server. You could use for example the Apache Jakarta Commons Net library to communicate with the server via FTP.
 
Collins Mbianda
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
I think Commons Virtual File System is interesting to access file systems.

It supports FTP, HTTP, HTTPS, SFTP, etc...

Hope it help !
Collins
 
somenath chatterjee
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sending you the code, but its giving me an exception please tell me how can i handle this exception-

package remoteFileTest;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.commons.net.ftp.*;

public class AccessRemotFile {

public static void main(String[] args) {

FTPClient ftp = null;
String usrID = "userID";
String pass = "password";
String url = "SystemIP";
//String fileName = "E:/vishal/vishal.txt";
File file = new File("E:/FOLDER/file.txt");

StringBuffer sb = new StringBuffer("ftp://");

sb.append(usrID);
sb.append(':');
sb.append(pass);
sb.append('@');
sb.append(url);
sb.append('/');
sb.append(':');
//sb.append(fileName);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
System.out.println("sb: "+sb);
try {


URL url2 = new URL(sb.toString());
URLConnection connection = url2.openConnection();

bos = new BufferedOutputStream(connection.getOutputStream());
bis = new BufferedInputStream(new FileInputStream(file.getName()));

int i;
while((i = bis.read())!=-1){
bos.write(i);
}
} catch (Exception e) {
System.out.println("Exception in AccessRemotFile: "+e);
e.printStackTrace();
}finally{
if (bis != null) try { bis.close(); } catch (Exception ioe) { /* ignore*/ }
if (bos != null) try { bos.close(); } catch (Exception ioe) { /* ignore*/ }
}

}

}




Exception :

Exception in AccessRemotFile: java.net.ConnectException: Connection refused: connect
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.NetworkClient.openServer(Unknown Source)
at sun.net.ftp.FtpClient.openServer(Unknown Source)
at sun.net.ftp.FtpClient.openServer(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(Unknown Source)
at remoteFileTest.AccessRemotFile.main(AccessRemotFile.java:42)
 
Collins Mbianda
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without using that programm,
Are you able to connect to SystemIP with ID "userID" and password "password"
from your post ?

It seem you don't have enough rigths to connect to that server.
 
Norm Radder
Ranch Hand
Posts: 894
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've nicely hidden the URL you're using and then didn't copy the println() of it with your error message.

It'd make it easier to help you if you'd show all the details of what is happening.

Also it would help if you would put an eye catching comment on line 42 where the error is.

As Collins asks:
Are you able to manually connect to that server from you computer? Ie bring up a telnet like screen and enter the command and see what happens.
[ June 27, 2008: Message edited by: Norm Radder ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic