Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.8k views
in Java FTP by
My large files (5mb approx) are not opening after being downloaded? I can see the file on my desktop where i saved it too, but when i double click to open it I get an error message from Microsoft Word saying "The document name or path is not valid".

For smaller files they are downloading and opening fine? Any idea as to what could be causing this?

Here is the code from my doGet() method of my servlet:
Integer documentID = new Integer(request.getParameter("documentID"));
         Integer employeeID = new Integer(request.getParameter("employeeID"));
         
         DocumentsMgr documentsMgr = documentsMgrHome.create();
         Document document = documentsMgr.getDocument(documentID);
         
         if (document != null) {         
            FTPConnectionMgr connectionMgr = new FTPConnectionMgr(host, user, password);
            if (request.getParameter("viewOnly") == null) {
               document = documentsMgr.checkOut(documentID, employeeID);
            }
            byte[] file = connectionMgr.getFile(document.getDocumentTitle());
            if (file.length > 0) {
               response.setContentType("application/x-download");
               response.setHeader("Content-Disposition","attachment; filename=\"" + document.getDocumentTitle() + "\"");
               ServletOutputStream out = response.getOutputStream();
               //connectionMgr.getFile(out, document.getDocumentTitle());   
               out.write(file);
               out.close();            
            }
            else {
               JErrorBean errorBean = new JErrorBean();
               errorBean.setErrorMessage("File " + documentID + " exists in the database but not on the file server, please contact an administrator");

               request.setAttribute("error", errorBean);
               request.getRequestDispatcher("error.jsp").forward(request, response);
            }
         }
         else {                        
            JErrorBean errorBean = new JErrorBean();
            errorBean.setErrorMessage("Problem retreiving document");

            request.setAttribute("error", errorBean);
            request.getRequestDispatcher("error.jsp").forward(request, response);
         }


And here is my FTP connection code:

public class FTPConnectionMgr {
   
   private FTPClient ftp;
   
   public FTPConnectionMgr(String host, String user, String password) {
      
      try {
         ftp = new FTPClient(host);
         ftp.debugResponses(true);
         ftp.login(user, password);
         ftp.setType(FTPTransferType.BINARY);
         ftp.setConnectMode(FTPConnectMode.ACTIVE);
      }
      catch (IOException ex) {
         throw new KMAFTPException(ex);
      }
      catch (FTPException ex) {
         throw new KMAFTPException(ex);
      }
   }
      
   public byte[] getFile(String remoteFileName) {
      try {
         byte[] file = ftp.get(remoteFileName);
         return file;
      }
      catch (FTPException ex) {
         return new byte[0];
      } 
      catch (IOException ex) {
         throw new KMAFTPException(ex);
      }
   }
}

3 Answers

0 votes
by (161k points)
Code looks ok. One approach could be to write the byte array out to file on the server and see if that is corrupted - if it is ok you know the problem is in the download from the servlet engine to your desktop. 5 mb is quite a lot to be sending via a servlet's output stream - maybe something is getting corrupted there.

My large files (5mb approx) are not opening after being downloaded? I can see the file on my desktop where i saved it too, but when i double click to open it I get an error message from Microsoft Word saying "The document name or path is not valid".

For smaller files they are downloading and opening fine? Any idea as to what could be causing this?

0 votes
by
Thanks for the help, I will try that...

Is there any other way to get files from a servlet to IE other than through an OutputStream that you know of?

Also, I am running the edtftp version from november 2003, have there been any bug fixes since then that looked at corrupted transfers?

I have recently moved my code to a new hosting provider, it worked fine before the move...do you know if hosting providers can do anything to server settings that might now be causing the files to be corrupted?

Thanks
Sian
0 votes
by (161k points)
There's been a few releases since then, but I don't think they would have relevant fixes for this problem.

Your new provider may well be using a completely different webserver. You could also try changing the content type of the response - they might be configured differently - e.g. application/octet-stream

Thanks for the help, I will try that...

Is there any other way to get files from a servlet to IE other than through an OutputStream that you know of?

Also, I am running the edtftp version from november 2003, have there been any bug fixes since then that looked at corrupted transfers?

I have recently moved my code to a new hosting provider, it worked fine before the move...do you know if hosting providers can do anything to server settings that might now be causing the files to be corrupted?

Thanks
Sian

Categories

...