package com.sinata.ministryoftransport.controller;
|
|
|
import com.alibaba.fastjson.JSON;
|
import com.sinata.ministryoftransport.util.FTPUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
/**
|
* FTP上传控制器
|
*/
|
@RestController
|
@RequestMapping("/ftp")
|
public class FTPController {
|
|
@Autowired
|
private FTPUtil ftpUtil;
|
|
|
/**
|
* 文件上传成功后移动到新的文件夹中
|
* @param path 文件上传路径
|
* @param fileName 上传文件名称
|
* @param url 上传文件网络地址
|
* @param newFilePath 移动到新的文件路径及新文件名称
|
*/
|
@ResponseBody
|
@PostMapping("/uploadAndMoveFile")
|
public String uploadAndMoveFile(String path, String fileName, String url, String newFilePath){
|
try {
|
//上传文件
|
boolean b = ftpUtil.uploadFile(path, fileName, url);
|
if(b){
|
//移动文件
|
boolean b1 = ftpUtil.moveFile(path + "/" + fileName, newFilePath);
|
if(b1){
|
System.out.println("移动文件成功");
|
return "上传文件成功";
|
}
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
return "上传文件失败";
|
}
|
}
|