Reputation: 31
I have a Spring Boot program that runs in a server, and it needs to read file from a different machine (Both machines are Windows OS). In the remote machine, I do not use any web-server such as apache/nginx - and I don't want to. I want to directly read files from the disk.
What I want is to provide the required params (probably IP, user name and password of the remote host), and a path in the file system - to direct access to the files without web server.
public void readFile(String ip, String userName, String password, String path);
How can I achieve this?
Upvotes: 0
Views: 1377
Reputation: 586
You can do something like
Upvotes: 1
Reputation: 7404
You need to do a scp
(which allows copying files from different machines) from Java. This library will help
Also a working example which copies a file from remote to local
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
...
String command = "scp -f "+rfile;
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
InputStream in = channel.getInputStream();
channel.connect();
// "in" contains the input stream of the file
Upvotes: 1