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
Related
I am working at an application in java from windows. I have to connect to a server. I only know the ip: 172.... and port. I want to obtain the last modified date for a file on that server. I have tried some methods but it doesn't work. I read a lot about http, ftp, sftp but this things are not clear for me, and i could not understand how to obtain the date. Please help me!
I have tried with urlConnection, with ftp etc..
On windows the file sharing protocol is CIFS.
You have a java Open source library which implement this protocol : jcifs
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.
How can i upload file in remote machine(LAN) using java program.I want to connect remote machine in LAN and upload file from my local machine to remote machine.So please tell me how can i do this.
I suggest you use JSch. You'll be able to connect easily to a remote machine and it allows you to execute file transfer using sftp for example.
It's hard to find a real documentation for JSch, but the various examples they give on their site are really complete and in general sufficient to help one succeeding in his task.
You probably want an HTTP client library for Java, to issue an HTTP POST request. (I assume the remote machine has some web server to upload the file).
Google gives several suggestions, like Hc.Apache
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/
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.