473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

access password protected system using java code

1
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...Please help!

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.InetAddress;
import java.net.PasswordAuthentication;
import java.net.URL;

public class Main {
public static void main(String[] argv) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL("http://10.201.74.231:80/C:\\test\\abc.doc");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
}
}

class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getPasswordAuthentication() {
String promptString = getRequestingPrompt();
System.out.println(promptString);
String hostname = getRequestingHost();
System.out.println(hostname);
InetAddress ipaddr = getRequestingSite();
System.out.println(ipaddr);
int port = getRequestingPort();

String username = "priyanka";
String password = "wipro_123";
return new PasswordAuthentication(username, password.toCharArray());
}
}
Mar 24 '11 #1
0 1561

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: aikwee | last post by:
hi, i want to do a read and write access to a XML file in a share folder with user name and password protected. I have the username and password provided but i don't know how to do it in VB.NET. ...
1
by: keyjen2017 | last post by:
i am trying to read the table in DB2 using JAVA code. then it is supposed to be copied in .txt file. how can i do this? other thing, i m passing date in dddd-mm-yy format from JAVA codeto call a ...
1
by: ravikiranveluguleti | last post by:
hi, this is ravikiran, I have a situation where i need to create an ms-access database with one table in it at runtime when an user clicks on a button in my front end. Is there any way to...
6
by: rahulbsbs | last post by:
Sir how can i get the ip address of the remote system by writting a java code,ie i want to get ip address of the remote system that is connected to my server computer ,the ip address must be obtained...
1
by: JagPeram | last post by:
Is it possible to return a xml object from a jsp using java code? here is my code: <html> <head><title>Page Title</title></head> <body> <table width="100%"> <tr> <td>
0
ganesht
by: ganesht | last post by:
Actually i have the jar file. If i release another version of that jar, I want to intimate that, when the user run the application(jar). That time i want to reinstall all the files while accept the...
1
by: comeshopcheap | last post by:
Hi I am using this script to access doba.com (I need to download some files) but I keep on being sent back to the login page not the user home page. Any help. I think I may need to use a post...
2
by: slink9 | last post by:
I have an Access database that I have recently had to password protect. I am using CR8.5 to do the reporting and it worked fine until I password protected the database. This is the code that...
3
by: shoby | last post by:
Hi, I need to execute an exe from a java application.The exe follows a partticular format when it is executed from command line. The format is as below: ( exe-name < input.txt ) > output.txt...
4
by: klwead123 | last post by:
i am try to read an object from .Net Webservice i got this type ArrayOfAnyType as in this lines of code: public class NewClass { try { // Call Web Service Operation ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.