|
@@ -37,17 +37,13 @@ public class SFTPUtil {
|
|
|
} else {
|
|
|
jsch.addIdentity(keyFilePath);// 设置私钥
|
|
|
}
|
|
|
- log.info("连接sftp,私钥文件路径:" + keyFilePath);
|
|
|
}
|
|
|
- log.info("SFTP Host: " + host + "; UserName:" + userName);
|
|
|
session = jsch.getSession(userName, host, port);
|
|
|
- log.debug("Session 已建立.");
|
|
|
Properties sshConfig = new Properties();
|
|
|
sshConfig.put("StrictHostKeyChecking", "no");
|
|
|
session.setConfig(sshConfig);
|
|
|
session.setConfig("kex", "diffie-hellman-group1-sha1");
|
|
|
session.connect();
|
|
|
- log.debug("Session 已连接.");
|
|
|
channel = (ChannelSftp) session.openChannel("sftp");
|
|
|
channel.connect(60000);
|
|
|
log.info("连接到SFTP成功.Host: " + host);
|
|
@@ -86,9 +82,8 @@ public class SFTPUtil {
|
|
|
try {
|
|
|
// fileName = "C:\\Users\\Administrator\\Desktop\\ftp\\upload\\1580697240002.xlsx";
|
|
|
// channel.put(new FileInputStream(fileName), "/download/1580697240002.xlsx", ChannelSftp.OVERWRITE);
|
|
|
- log.info("dis == " + dir);
|
|
|
channel.put(new FileInputStream(fileName), dir, ChannelSftp.OVERWRITE);
|
|
|
- log.info("上传到sftp成功");
|
|
|
+ log.info("上传到sftp成功,文件名:{}", fileName);
|
|
|
} catch (Exception e) {
|
|
|
log.info("上传文件:" + fileName + "失败");
|
|
|
throw e;
|
|
@@ -119,7 +114,6 @@ public class SFTPUtil {
|
|
|
List<String> files = listFiles(remotePath);
|
|
|
for (String fileName : files) {
|
|
|
output = new FileOutputStream(localPath + "/" + fileName);
|
|
|
- log.info("下载文件:" + fileName + "开始");
|
|
|
channel.get(remotePath + "/" +fileName, output);
|
|
|
log.info("下载文件:" + fileName + "成功");
|
|
|
delete(remotePath, fileName);
|