Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

FTP upload file from HTML input form

 
Greenhorn
Posts: 10
  • 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
 
Rancher
Posts: 43016
76
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry can you link me any samples?

thank you for your answer!
bye
 
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
  • 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
Posts: 43016
76
  • 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
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
  • 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.

 
Marshal
Posts: 25798
69
Eclipse IDE Firefox Browser MySQL Database
  • 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
  • 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
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
Bartender
Posts: 2658
19
Netbeans IDE C++ Linux
  • 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
  • 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
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • 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.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic