File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FTP upload file from HTML input form

 
Luca Verdi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I'm writing a servlet 3.0 for handle FTP upload. The home page is a JSP page with a simple HTML form like this:


Servlet have the @Multipartconfig decoration. I'm using common-io and common-net library too.
How can I upload the file? I can't use InputStream or similar because i can't get file path from an HTML form!
What I wrong?
What is the best practice to do this?

tnx and sorry my bad english!
bye
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML forms use HTTP, not FTP, so an "FTP file upload" is not possible. You can do an HTTP file upload, and handle it on the server using a library such as Apache Commons FileUpload.
 
Luca Verdi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry can you link me any samples?

thank you for your answer!
bye
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the ServletsFaq and the JspFaq for more information.
 
Luca Verdi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is, for example, an Applet a good way to do this work? Instead JSP/Servlet technology?
tnx
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An applet runs on the client; it changes nothing about the server side. Are you saying an HTTP upload is out of the question? The servlet could put the file onto the FTP server after the HTTP upload.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Applets should not be used for modern sites.
 
Luca Verdi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok but, in my scenario, user browser (client) and server can comunicate only by FTP protocol (SFTP particular).
I think that server is protect inside a lot of firewalls. Next will be done a iptable rule to avoid file upload and other stuff.

I need to write a web application (next to deploy on Liferay) that can do this. User needs to put a file on server via (S)FTP.

 
Paul Clapham
Sheriff
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't get confused by the names: SFTP is not a version of FTP. It's more like a version of SSH. At any rate it isn't supported in browsers. I think you should consider having your clients install SFTP client software and using that. This is going to be directed at a small list of clients, rather than open to the general public, right?
 
Luca Verdi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:An applet runs on the client; it changes nothing about the server side. Are you saying an HTTP upload is out of the question? The servlet could put the file onto the FTP server after the HTTP upload.


Continue please. I'm very interest!
If I've just finished the HTTP upload, the file is already on server, isn't true?

Like I sad before (but after your answer :P ) the only way to communicate with server is over FTP. I think that HTTP upload could be blocked!
Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If HTTP is blocked, how were you expecting to show a web page to the user in the first place?

If SFTP must be used, and HTTP is blocked, then using an existing SFTP client seems the only logical approach.
 
Jan Cumps
Bartender
Posts: 2576
11
C++ Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing that I've seen working that faintly behaves like this is some web served java application.
An example is http://www.javaftp.com/

I got 3 security warnings from my Firefox browser on Linux before I was allowed to run it
 
Luca Verdi
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok this is the way:
Client ------- HTTP --------> Tomcat (servlet) ------ SFTP -------> Server

Tomorrow I'll test all of this and notify you if it is right.
Tnx

Bye
 
Richard Tookey
Bartender
Pie
Posts: 1166
17
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luca Verdi wrote:Ok this is the way:
Client ------- HTTP --------> Tomcat (servlet) ------ SFTP -------> Server

Tomorrow I'll test all of this and notify you if it is right.
Tnx

Bye


I see no point in this! You copy the file from the client in an insecure manner (HTTP) to a server then copy the file again from the server to the server securely using SFTP! Since the file is on the server after the HTTP copy why do you need the second copy stage?

It seems to me that all you need it to use HTTPS (maybe with client authentication) to copy the file from the client to the server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic