• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FTPing files from HTML form

 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How do I FTP files form my html form using <input type="file"> to the server?
thanks,
Alex
 
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this
http://jakarta.apache.org/commons/fileupload/
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!
Is there an example of where I can see how to use this FileUploader?
thanks,
Alex
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you? This way I will at least have some real example reference.
thanks a lot,
Alex
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, got it working. Can you give that Excel upload example?
thanks,
Alex
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic