Transfer files from Unix to Winxp server using Jsch - java

I'm writing a Java program, to transfer files from Unix server to Windows using the JSch library :)
Maybe someone could help me find some example code on how to download a file? I am looking for functions something like these:
Jsch new= Jsch();
new.downloadFilesFromServer(String filename);
new.saveFileLocation(String location) // i mean the right function names
I tried the simple JSch example and I can connect to server, complete one operation, and disconnect. So far the only functions I've found in documentation were more-or-less connecting to the server or disconnecting, but not the file download functions, or a JSch full tutorial (if one exists :D ).

Take a look at the ScpFrom jsch example which shows you how to copy a remote file to somewhere local.

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

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.

SFTP to retrieve files from Windows server to Linux server using java

I am working on file download functionality.All my files are in Windows server,is there any Library in java which can be used to do SFTP to transfer files from remote windows server to Linux server where my Java app is running?
use JScape's secure FTP library from this link
given you have access to both peers, you can use SSLServerSocketFactory/SSLSocket for the connection on both ends.
Edit:
some basic example on how to establish connection and read/write data: http://stilius.net/java/java_ssl.php
wow, hope you are satisfied with our software :)
thank you,

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