• 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

How to read a file from remote System

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDBC wouldn't help you with that. Let's move this somewhere more appropriate.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic