(reposted)

First of all, thanks to everyone who contributes to this mailing list and
others like it.

I have a Servlet that opens a URLConnections and reads a file stream from an
ftp server. The file dowloads up to a certain point and then stalls just
before completing download. I've included the code for any Java gurus who
want to take a stab at it.

this behavior works the same for Navigator 4.08 and IE 5.5, unlike HTTP
dowload, where Content-Disposition works in Navigator and not in IE. But
that's another post :) TIA

Neill Laney

http://home.nc.rr.com/nlaney

--

Web Developer/Technical Support Specialist.

--



import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.net.*;

public class Download extends HttpServlet {

public void service(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {


response.setContentType("application/octet-stream");

String filename = request.getParameter("filename");

String test = "ftp://updates.redhat.com/7.0/i386/bind-8.2.3-1.i386.rpm";

URL u = null;

URLConnection uc = null;

InputStream d = null;

OutputStream out = response.getOutputStream();


try {


u = new URL(test);

uc = u.openConnection();

d = uc.getInputStream();

int index = u.getFile().lastIndexOf("/") + 1;

filename = u.getFile().substring(index);

System.out.println (filename);

response.setHeader("Content-Disposition","attachment; filename=" +
filename);


int size = 0;

byte [] b = new byte[1024];



while((size = d.read(b, 0, 1024)) > 0)

out.write(b, 0, size);

d.close();

out.flush();

out.close();

}catch(Exception e) {}


}

}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to