Here is the code:
private class FtpFile {
public FtpFile( String url, String fname) throws Exception
{
URL site = new URL(url);
URLConnection siteCon = site.openConnection();
siteCon.setDoInput(true);
siteCon.setDoOutput(true);
siteCon.connect();
System.out.println("Allowed interaction is " + siteCon.getAllowUserInteraction() + siteCon.getDoOutput() );
OutputStream out = siteCon.getOutputStream();
// Send the file out
File file_in= new File(fname);
FileInputStream is= new FileInputStream(file_in);
int c;
byte[] bytes = new byte[1024];
int total_bytes=0;
while((c=is.read(bytes)) !=-1)
{
total_bytes +=c;
out.write(bytes,0,c);
}
out.flush();
out.close();
//Verify that the file is there
int read_bytes = 0;
site = new URL(url+"//"+fname);
siteCon = site.openConnection();
siteCon.setDoInput(true);
siteCon.connect();
InputStream in = siteCon.getInputStream();
while((c=in.read(bytes)) != -1)
{
read_bytes += c;
}
System.out.println("File read from destination, total bytes = " + read_bytes);
}
}
Savithri