aspose file tools*
The moose likes Linux / UNIX and the fly likes Upload a file to unix and invoke a java method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Upload a file to unix and invoke a java method " Watch "Upload a file to unix and invoke a java method " New topic
Author

Upload a file to unix and invoke a java method

Cindy Jones
Ranch Hand

Joined: Oct 08, 2002
Posts: 66
I need to upload a file to a file on a unix machine and process that file using some additional parameters.
One way of doing this is to have a web application using which I can upload the file to the unix system and which also accepts the additional parameters.
However my unix machine does not have any webservers and we are not planning on having one unless absolutely necessary.
The alternative is to upload the file using WinSCP, and run the java code that processes the file from the console.
Are there any other alternatives? I thought that running a Swing FileChooser might be the answer, but not anymore (1. FileChooser would let me choose files on the UNIX box and not on my local machine 2. To get Swing to work I have to have X11 installed)
Any suggestion would be appreciated!

Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Personally, I'd use a web app. But how about using a simple FTP server and run a daemon on the machine that detects when new files have been uploaded and triggers the post-upload actions?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

P.S. At a previous job we did this with email. The clients would email files as attachments and the email server would store the messages in the file system. A daemon detected new messages, fetched the attachments, and processed them.

FTP would be cleaner, but these clients were very technically-challenged and getting them to use email was about as technical as they could get.
Cindy Jones
Ranch Hand

Joined: Oct 08, 2002
Posts: 66
The problem with using the FTP server is that the users also need to pass some additional parameters.
Thanks for your suggestions - now I know I am not missing any obvious solutions and that the webserver route might be the way to go after all.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

We do that by first uploading the file to the FTP server, then using the FTP "RCMD" command to run the program which processes the file.

It takes a bit of configuration to get the path set up on the server, and so on. And you should be careful with security if your FTP server is exposed to the Internet (allowing anybody in the world to potentially execute arbitrary commands on your FTP server would be dangerous).
Cindy Jones
Ranch Hand

Joined: Oct 08, 2002
Posts: 66
I am on the lookout for a solution that would appeal to "technology challenged" clients
Thanks for your your tips!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Hmmm, if the web app route doesn't pan out, perhaps the email solution, where the extra information could be sent in the body of the email, might serve?
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

There are some Java libraries for SSH which might work well if the Unix box runs OpenSSH, uploading the file with SCP or SFTP, then running the command through the shell. Have a look at JSch and Trilead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Upload a file to unix and invoke a java method