Java实现上传文件到服务器指定目录的方法
发布时间:2020-08-03 10:49:31
来源:亿速云
阅读:74
作者:小猪
这篇文章主要讲解了Java实现上传文件到服务器指定目录的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
前言需求
使用freemarker生成的静态文件,统一存储在某个服务器上。本来一开始打算使用ftp实现的,奈何老连接不上,改用jsch。毕竟有现成的就很舒服,在此介绍给大家。
具体实现
引入的pom
ch.ethz.ganymed
ganymed-ssh3
262
com.jcraft
jsch
0.1.55
建立实体类
public class ResultEntity {
private String code;
private String message;
private File file;
public ResultEntity(){}
public ResultEntity(String code, String message, File file) {
super();
this.code = code;
this.message = message;
this.file = file;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
}
public class ScpConnectEntity {
private String userName;
private String passWord;
private String url;
private String targetPath;
public String getTargetPath() {
return targetPath;
}
public void setTargetPath(String targetPath) {
this.targe