![](/img/trans.png)
[英]How to upload a file by transfering the file from the local machine to the remote web server using Selenium Grid
[英]Read file from remote machine without web server
我有一个在服务器中运行的 Spring 引导程序,它需要从不同的机器读取文件(两台机器都是 Windows 操作系统)。 在远程机器上,我不使用任何网络服务器,例如 apache/nginx - 我也不想。 我想直接从磁盘读取文件。
我想要的是提供所需的参数(可能是 IP,远程主机的用户名和密码),以及文件系统中的路径 - 在没有 web 服务器的情况下直接访问文件。
public void readFile(String ip, String userName, String password, String path);
我怎样才能做到这一点?
您需要从 Java 执行scp
(允许从不同机器复制文件)。 这个图书馆将帮助
也是一个将文件从远程复制到本地的工作示例
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
你可以做类似的事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.