Forums Register Login

downloading zip files from a site to local disk(urgent please)

+Pie Number of slices to send: Send
hello friends:
iam doing a project in java networking.
iam connecting to a site(http or ftp) having userid and password.
code for this is given below,and i want to download the
files in that site to the local disk, but that site contains zip file,i want to download that zip file as it is to the local disk creating a file folder in the local disk.
how it can be done?
help urgently please
import java.io.*;
import java.net.*;
class zipfold
{
public static void main(String args[])
{
String url=null;
String userid=null;
String passwd=null;

try
{
BufferedReader bo=new BufferedReader(new InputStreamReader(System.in));
System.out.println("entet the userid");
userid=bo.readLine();
System.out.println("entet the password");
passwd=bo.readLine();
System.out.println("entet the url");
url=bo.readLine();
URL u=new URL(url);
String compress= userid+":"+passwd;
String encoding=new sun.misc.BASE64Encoder().encode(compress.getBytes());
URLConnection uc= u.openConnection();
uc.setRequestProperty("Authorization","Basic "+encoding);
InputStream content = (InputStream)uc.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader (content));
String line;
FileOutputStream fo=new FileOutputStream("c:/dinesh1/springer.html");
while ((line = in.readLine()) != null) {
System.out.println (line);
byte b[]=new byte[line.length()];
b=line.getBytes();
fo.write(b);
}
}catch(Exception e){System.out.println(e);}
} //function main
} //class

------------------
+Pie Number of slices to send: Send
Jeff Holmes was kind enough to donate an ftp client implementation using sockets. This should meet your needs.
Hope this helps
+Pie Number of slices to send: Send
You can try the FtpBean component at the following address.
I used it already it it works perfectly.
www.geocities.com/SiliconValley/Code/9129/javabean/ftpbean
Eric
I just had the craziest dream. This tiny ad was in it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1121 times.
Similar Threads
url connection: IOException-socket closed
Writing data into file from URL address
How to read html file?
problem in using zipinputstream class
problem with ZipInputStream
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:25:10.