aspose file tools*
The moose likes JSP and the fly likes FTPing files from HTML form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "FTPing files from HTML form" Watch "FTPing files from HTML form" New topic
Author

FTPing files from HTML form

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Hi,
How do I FTP files form my html form using <input type="file"> to the server?
thanks,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
check this
http://jakarta.apache.org/commons/fileupload/
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks!
Is there an example of where I can see how to use this FileUploader?
thanks,
Alex
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
check the documentation. Its very clear.
If it is to the server give the file path. I am uploading an excel file and reading it. So my code wont be useful to you. If you still want it i can send
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
can you? This way I will at least have some real example reference.
thanks a lot,
Alex
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Sunitha,
Also, aside from using FileUpload I have trouble using it in my page. Where exectly do I have to copy commons-fileupload-1.0.jar? And how do I reference it's location in JSP: import org.apache.commons.fileupload.* ?
thanks again,
Alex
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
If its tomcat put the jar file in commons/lib
and start the server and tehn in your code import these:
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.DiskFileUpload;
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
I am using Unify eWave, and their file structure is /var/apache/htdocs/application/WEB-INF/classes. Should I make directory commons/lib under WEB-INF/classes?
thanks,
Alex
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
ok, got it working. Can you give that Excel upload example?
thanks,
Alex
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
public void handleRequest(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{ HttpSession session=request.getSession(false);
PrintWriter out=response.getWriter();
//check there is a file Upload Request
try
{
DiskFileUpload up=new DiskFileUpload();

if(!DiskFileUpload.isMultipartContent(request))
{
String nextstop="/FileUploadErr.jsp";
RequestDispatcher rd=this.getServletContext().getRequestDispatcher(response.encodeURL(nextstop));
if(rd==null){

response.setContentType("text/html");
out.println("<html><title>PATH</TITLE></HEAD>");
out.println("<body>The path could not be found!</body></htm>");
}
else{
System.out.println("Forwarding");
rd.forward(request,response);
}
}

else{

response.setContentType("text/html");
up.setSizeMax(1000000);
up.setSizeThreshold(4096);

// up.setRepositoryPath(repositoryPath);
List fileItems=up.parseRequest(request);
Iterator i=fileItems.iterator();
while(i.hasNext())
{
FileItem fi=(FileItem)i.next();
String contentType;
String fileType=fi.getContentType();
String fileName=fi.getName();
boolean isInMemory=fi.isInMemory();
long sizeInBytes=fi.getSize();

out.println("Printing the file name"+fileType+sizeInBytes+fileName+isInMemory);
if(fileType.equals("application/vnd.ms-excel"))
{

//rest for teh excel
hth
sunitha
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
thanks!
But will this upload files into directory where Servlet is or can I specify where files should go. In my case I need to specify server name like 122.22.34.44, login to it and upload files there by changing directories.
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
yes u can .check the code
up.setRepositoryPath(repositoryPath)
repositoryPath is path where you want to upload the file
so
repositoryPath="c/temp"
hth,
sunitha
 
Consider Paul's rocket mass heater.
 
subject: FTPing files from HTML form