Write file to another UNIX server - java

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.

Related

How to download remote files in Java

There are some posts regarding how to read from/write to a file in a remote system. However, I haven't found one useful to my purposes and I hope you can help me out.
So far, I have a java program that can connect to a server using sockets. The remote system (server) is not in the LAN which I think makes it more complicated to access files in that computer. The purpose of my "networking program" is to download files that are in the remote server and I can achieve this by copying bytes of the file once I have reached it, but I don't know how to "navigate" through the directories of the server. The only thing I've done so far is to connect to it.
The remote server runs on Linux. I'm trying to find out how to do this and I came across with JSch. I have not read too much about it but I would like to ask you if this is possible with JSch or what is the solution you would use.
JSch can surely work.
Refer this: File download

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.

Run java from FTP

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.

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/

how to automatically and periodically upload a file from a windows machine to a unix server?

i have 2 csv files on my windows machine that i want to transfer to a unix server every hour (because the 2 files are updated every 30min).
so i search on the web and i found this possibility: to ftp the files from windows to unix using a batch and task scheduler.
i want to know if it's possible to do it from the unix server with a cron job or with java timer and not from the windows machine and if if there's other easier solutions.
thanks for your help
The main problem you would have is in allowing the Unix machine to access a Windows file.
You didn't specify what kind of networking configuration you use and what version of Windows it is, as some later versions provide facilities for file sharing across platforms.
In the worst case, you could set up an FTP (or SFTP) server on your windows machine, share a specific directory in which you will put the file, and then write a script on the UNIX that will download the file from the windows machine. A variation on this is to install a web server on the windows machine, and have the script on the unix make an HTTP request for the file.
You could install a webserver like http://www.aprelium.com/abyssws/
It seems to be free and should be not that hard to set up. Afterwards put your files in the htdocs-folder and configure your Vista-firewall to let requests on port 80 pass.
Then you can access your files via
http://IPofYourWindowsComputer/yourfile.zip
If you want to access your windows machine from outside your local network you'd have to setup your router to forward port 80 to your windows machine. Otherwise the machine from outside will be blocked by the router.
PS: Samba (SMB) just works within the same LAN. If you are you could create a shared folder and put the files in there and access them via smbclient or mount.
PPS: Maybe your question is better placed # http://serverfault.com

Categories

Resources