access password protected system using java code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • netri
    New Member
    • Mar 2011
    • 1

    access password protected system using java code

    I need to write a java program in which i need to access a computer in my network using IP address but system is password protected.so how can i access a password protected system to fetch a file from specified location and use store in my system?


    I got a code from google but its not working...Pleas e help!

    import java.io.Buffere dReader;
    import java.io.File;
    import java.io.InputSt reamReader;
    import java.net.Authen ticator;
    import java.net.InetAd dress;
    import java.net.Passwo rdAuthenticatio n;
    import java.net.URL;

    public class Main {
    public static void main(String[] argv) throws Exception {
    Authenticator.s etDefault(new MyAuthenticator ());
    URL url = new URL("http://10.201.74.231:8 0/C:\\test\\abc.d oc");
    BufferedReader in = new BufferedReader( new InputStreamRead er(url.openStre am()));
    String str;
    while ((str = in.readLine()) != null) {
    System.out.prin tln(str);
    }
    in.close();
    }
    }

    class MyAuthenticator extends Authenticator {
    protected PasswordAuthent ication getPasswordAuth entication() {
    String promptString = getRequestingPr ompt();
    System.out.prin tln(promptStrin g);
    String hostname = getRequestingHo st();
    System.out.prin tln(hostname);
    InetAddress ipaddr = getRequestingSi te();
    System.out.prin tln(ipaddr);
    int port = getRequestingPo rt();

    String username = "priyanka";
    String password = "wipro_123" ;
    return new PasswordAuthent ication(usernam e, password.toChar Array());
    }
    }
Working...