|  |  |  | 
|---|
|  |  |  | package com.moral.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.apache.commons.net.ftp.FTPClient; | 
|---|
|  |  |  | import org.springframework.security.access.method.P; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.BufferedReader; | 
|---|
|  |  |  | 
|---|
|  |  |  | @CrossOrigin(origins = "*", maxAge = 3600) | 
|---|
|  |  |  | public class UpgradeController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private FTPClient ftpClient; | 
|---|
|  |  |  | private String fileName = "Version.xml"; | 
|---|
|  |  |  | private String ip = "121.40.92.176"; | 
|---|
|  |  |  | private String userName = "ftp_user"; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/index", method = RequestMethod.GET) | 
|---|
|  |  |  | public String index() throws IOException { | 
|---|
|  |  |  | ftpClient = new FTPClient(); | 
|---|
|  |  |  | FTPClient ftpClient = new FTPClient(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ftpClient.connect(ip, port); | 
|---|
|  |  |  | ftpClient.login(userName, userPwd); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String content = readFile(ftpClient); | 
|---|
|  |  |  | if(ftpClient.isConnected()) { | 
|---|
|  |  |  | ftpClient.logout(); | 
|---|
|  |  |  | ftpClient.disconnect(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return readFile(); | 
|---|
|  |  |  | return content; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String readFile() { | 
|---|
|  |  |  | public String readFile(FTPClient ftpClient) { | 
|---|
|  |  |  | InputStream ins = null; | 
|---|
|  |  |  | StringBuilder builder = null; | 
|---|
|  |  |  | try { | 
|---|