后端
@GetMapping("/downloadPic")
@ResponseBody
public Result downloadPic(@RequestParam(“path”) String path, HttpServletResponse response) throws Exception {
String host = “116.255.145.237”;
int port = 21;
String username = “ftpuser”;
String password = “yw_ftp123”;
FTPClient ftp = new FTPClient();
String remotePath = path.substring(0, path.lastIndexOf("/"));
String fileName = path.substring(path.lastIndexOf("/")+1);
String stringData = “”;
try {
int reply;
ftp.connect(host, port);
// 如果采用默认端口,可以使用ftp.connect(host)的方式直接连接FTP服务器
// 登录
ftp.login(username, password);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
}
ftp.enterLocalPassiveMode();
// 转移到FTP服务器目录
ftp.changeWorkingDirectory(remotePath);<