wood burning stoves 2.0*
The moose likes Servlets and the fly likes FTP upload file from HTML input 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 » Servlets
Bookmark "FTP upload file from HTML input form" Watch "FTP upload file from HTML input form" New topic
Author

FTP upload file from HTML input form

Luca Verdi
Greenhorn

Joined: Feb 08, 2013
Posts: 10
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
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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.


Ping & DNS - my free Android networking tools app
Luca Verdi
Greenhorn

Joined: Feb 08, 2013
Posts: 10
sorry can you link me any samples?

thank you for your answer!
bye
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

See the ServletsFaq and the JspFaq for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luca Verdi
Greenhorn

Joined: Feb 08, 2013
Posts: 10
Is, for example, an Applet a good way to do this work? Instead JSP/Servlet technology?
tnx
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
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

Joined: Jan 10, 2002
Posts: 61434
    
  67

No. Applets should not be used for modern sites.
Luca Verdi
Greenhorn

Joined: Feb 08, 2013
Posts: 10
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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Feb 08, 2013
Posts: 10
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

Joined: Jan 10, 2002
Posts: 61434
    
  67

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

Joined: Dec 20, 2006
Posts: 2503
    
    8

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


OCUP UML fundamental and ITIL foundation
youtube channel
Luca Verdi
Greenhorn

Joined: Feb 08, 2013
Posts: 10
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 1067
    
  10

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.
 
 
subject: FTP upload file from HTML input form