Run java from FTP - java

How can I run a .jar (Java) file on a server using FTP? I use the ftp command to enter the server, provide the IP address, username, password. Is it possible to run the java file?

You cannot invoke non-ftp commands using ftp. Use ssh to access remote shell and invoke your commands.

FTP is File Transfer Protocol. It's supposed to be used for manipulating files only.
If you need to run a Java file, I suggest you use SSH, RSH, Telnet, or some other method of getting an actual shell.

You could use FTP to transfer your jar, and then use a crontab, or any other sort of scheduled task, to actually run it. It is not possible to execute commands using FTP.

I believe you mean using ssh command to enter the server and if so
I think this might be a starting point :
Can I run .jar file on Tomcat?
if not I don't think its possible.

Related

Write file to another UNIX server

Currently I am using weblogic for application server and it is running in one machine. I have to write the pdf(or any file type) to another Unix server. Can anyone please help me find the solution.
One solution is to mount the remote directory to your local server via smb or NFS (keyword sharing). Then you don't have to put any code for the copy job into your application. Instead the operating system will take care for the operation.
A simple and raw solution would be a SSH connection. There exists several Java libraries for SSH such as http://www.jcraft.com/jsch. Open a connection, write your file, close the connection. Of course you need the corresponding SSH keys and privileges to do this on the remote machine.

Make SSH Connection and Run An Executable in Java

I want to connect to a server using ssh and run an executable on the server from my local Java code. I am aware of the thread SSH connection with Java but the trouble is I can not figure out how to use sftpChannel (an object of ChannelSftp) to run a file rather than open a file.
If this can not be done using JSch, how should I do if I want to call a exe file remotely in Java.
Thanks very much!
You need to use ChannelSsh, not ChannelSftp to run a remote command.
http://epaul.github.io/jsch-documentation/javadoc/

Connecting to Hadoop from Java app using SSH

I'm trying to connect to remote hadoop cluster, which isn't accessible just through HDFS. Right now it is being used in that way: user connects to Jump box through SSH (e.g. ssh user#somejumboxhost.com), then from jump box server we do connect to hadoop also with ssh (e.g. ssh user#realhadoopcluster1.com). What I'm trying to do is to access files from my Scala/Java application using HDFS client. Now I'm feeling like in Matrix - "I must go deeper" and don't know how to reach the server.
May be someone had similar experience? Right now I'm trying to connect to first server with SSH client from my app, but then I don't know how to call the HDFS client.
Any ideas will be appreciated, thanks!
I can think of something like this . There is "ganymed-ssh2" api which helps you to connect to some server using ssh and run unix command from there. Using this you can connect to your jumo box.
And from there you can run command as " ssh user#realhadoopcluster1.com hadoop fs somthing"
As we can run commands with ssh like this.
From your jump box, setup a password less ssh to your hadoopcluster machine. or you can use sshpass with password.
You can visit following link to check how to use this api:
http://souravgulati.webs.com/apps/forums/topics/show/8116298-how-to-execute-unix-command-from-java-
Hadoop is implemented in Java, so you could just run the Hadoop cluster directly from your application. Use Java RMI if it's a remote cluster. This extra pipework you're trying to do makes no sense.

How can I duplicate files on a SFTP server using JSch?

I faced problem to copy(duplicate) a file from one SFTP folder to another one on the same server.
So, question: Is there a some effective method to do it remotely (i.e. without copying a data to client and vice-versa)?
I am using Java with the JSch library.
The SFTP protocol itself does only support data transfer between client and server, not on the server itself.
You can use other parts of the underlying SSH protocol (and JSch's implementation therof) to execute a command on the server, though. In this case, as mentioned by Joop, an Exec channel is the right thing to use. You can use the same Session you have used for your ChannelSftp also for any number of other channels, e.g. for your exec channel. Just make sure to close any channels after use. (Have a look at the Shell, Exec or Subsystem Channel page at the JSch wiki for some more info.
This will of course not work if the server doesn't support command execution, e.g. if it is configured to only support SFTP. Then your only solution is to download and re-upload this file.
In SFTP one possibly can execute ! ... which is execute local command.
! cp a.txt a-backup.txt
As JSch also can give an SSH connection, even the exclamation sign is moot.
For code you might find some starting point in the examples. The Exec sample should do.

Java upload files to remote linux server WITHOUT ftp or scp

I am trying to write a program in java to upload some files from my local environment to a remote server. I cannot use FTP because there is no FTP server installed on that instance. Also port 22 is closed so I can't use scp either.
Is there any other way to approach this?
Thanks in advance guys!
You need something on the serverside, a program, which is waiting for your file. You can't just send something there.
An open port is always a program running, waiting for a connect.
So a couple of possible protocols are rsync and WebDav. But at the end of the day I recommend one of two options. Get ssh installed, or use rsync.
Talk to the unix admin and work something out.
Even linux servers sometimes use smb/cifs (the Microsoft technique to share files and folders) to publish data. The samba team provides a 100% Java library to access those: http://jcifs.samba.org/

Categories

Resources