【发布时间】:2019-07-25 06:58:56
【问题描述】:
我正在开发一个实现 REST API 的微服务。就是把某些文件从一个共享的网络位置上传到一个FTP服务器上。
这是一个示例代码:
@RequestMapping(method = RequestMethod.GET, value = "/ftpProcess", produces = "text/plain")
public String ftpFiles() throws UnknownHostException {
String status = "" ;
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession("ftpUserName", "ftpHost", 10022);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("ftpPassword");
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
//Just an example - I wull upload 4 dummy files
for(int i=1; i<4; i++) {
sftpChannel.put(/*Here I navigate to a file, and repeat it 3 times for 3 different files*/);
}
sftpChannel.exit();
session.disconnect();
status = "SUCCSSES" ;
}
在一个真实的应用程序中,我可能有不同的 ftpServer/host、用户和密码,所以它们必须作为参数进来。 我知道我可以使用@PathVariable 或@parameters 来做到这一点——通过HTTP GET 来做到这一点,但这样每个人都会看到传递了什么。
我怎样才能传递输入的信息,使其保密?
【问题讨论】:
标签: spring model-view-controller microservices