|
|
|
@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create by yixian at 2019-01-08 3:26
|
|
|
|
@ -66,15 +67,15 @@ public class TradeSecureServiceHanyinImpl implements TradeSecureService {
|
|
|
|
|
Channel channel = session.openChannel("sftp");
|
|
|
|
|
channel.connect();
|
|
|
|
|
command = (ChannelSftp) channel;
|
|
|
|
|
command.ls("/royalpay");
|
|
|
|
|
String dir = "/royalpay/" + file.getTransDate().toString("yyyyMMdd");
|
|
|
|
|
logger.debug("removing dir:{}", dir);
|
|
|
|
|
command.rmdir(dir);
|
|
|
|
|
logger.debug("rmdir success");
|
|
|
|
|
logger.debug("mk dir:{}", dir);
|
|
|
|
|
command.mkdir(dir);
|
|
|
|
|
String dateString = file.getTransDate().toString("yyyyMMdd");
|
|
|
|
|
Vector<ChannelSftp.LsEntry> folders = command.ls("/royalpay");
|
|
|
|
|
String dir = "/royalpay/" + dateString;
|
|
|
|
|
if (folders.parallelStream().noneMatch(entry -> entry.getFilename().equals(dateString))) {
|
|
|
|
|
logger.debug("mk dir:{}", dir);
|
|
|
|
|
command.mkdir(dir);
|
|
|
|
|
}
|
|
|
|
|
String dest = dir + file.filename();
|
|
|
|
|
logger.debug("rmdir success, start uploading file:{}", dest);
|
|
|
|
|
logger.debug("find dir, start uploading file:{}", dest);
|
|
|
|
|
command.put(new ByteArrayInputStream(file.content()), dest);
|
|
|
|
|
} catch (IOException | JSchException | SftpException e) {
|
|
|
|
|
throw new ChannelNetworkException("Upload Secure file failed", e);
|
|
|
|
|