jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Why I cannot do ftp in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why I cannot do ftp in servlet" Watch "Why I cannot do ftp in servlet" New topic

Why I cannot do ftp in servlet

xiaorui chen

Joined: Sep 05, 2000
Posts: 9
I am able to do ftp in standalone application.
However, when I put the similar code in servlet, the servlet hang for a long while, then "The page cannot be displayed".
I can see in the log file that the conenction is fine, it hangs when ftp begin to do the real transfer of the data part.

import java.io.*;

public class FtpServlet extends HttpServlet {

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

String server = "";
int port = 21;
String username = null;
String password = null;
String filename = null;
String rdir = null;
String ldir = null;

PrintWriter out = new PrintWriter(res.getOutputStream());
rdir = req.getParameter("rdestination");
ldir = req.getParameter("lsource");
String lfname = req.getParameter("lfname");
String rfname = req.getParameter("rfname");
if(rfname == null) {
rfname = lfname;
else if(rfname.trim().equals("")) {
rfname = lfname;
else {
rfname = req.getParameter("rfname");

FTPC ftpclient = null;
try {

ftpclient = new FTPC(server, 21, true);
ftpclient.login("sss", "sss");
ftpclient.storeFile(rfname, ldir + "/" + lfname, 1);

}catch(FTPException ftpe) {

Anshuman Purohit

Joined: Jan 24, 2004
Posts: 1
use FTPServlets instead of HTTPServlet.

Anshuman Purohit<br />SCJP
I agree. Here's the link: http://aspose.com/file-tools
subject: Why I cannot do ftp in servlet
It's not a secret anymore!