diff --git a/src/main/java/com/xydl/cac/iec/IecClient.java b/src/main/java/com/xydl/cac/iec/IecClient.java index d87fbb0..c671ea3 100644 --- a/src/main/java/com/xydl/cac/iec/IecClient.java +++ b/src/main/java/com/xydl/cac/iec/IecClient.java @@ -11,6 +11,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -168,11 +169,14 @@ public class IecClient implements ClientEventListener { } public void getFile(String remotePath, String localPath, Integer todel) throws Exception { - GetFileAction gfa = new GetFileAction(localPath); + String tmpFile = localPath + ".tmp"; + GetFileAction gfa = new GetFileAction(tmpFile); clientAssociation.getFile(remotePath, gfa); if (todel != null && todel == Constants.TRUE) { clientAssociation.deleteFile(remotePath); } + File file = new File(tmpFile); + file.renameTo(new File(localPath)); } @Override diff --git a/src/main/java/com/xydl/cac/iec/IecServerService.java b/src/main/java/com/xydl/cac/iec/IecServerService.java index 38cc22b..f02518d 100644 --- a/src/main/java/com/xydl/cac/iec/IecServerService.java +++ b/src/main/java/com/xydl/cac/iec/IecServerService.java @@ -64,7 +64,7 @@ public class IecServerService { } public void stopServer(Integer fileId) { - this.onlyStopServer(fileId); + this.doStopServer(fileId); Optional optional = fileRepository.findById(fileId); if (optional.isPresent()) { IcdFile icdFile = optional.get(); @@ -73,7 +73,7 @@ public class IecServerService { } } - private void onlyStopServer(Integer fileId) { + private void doStopServer(Integer fileId) { IecServer iecServer = StaticVariable.iecServerMap.get(fileId); if (iecServer != null) { iecServer.stop(); @@ -87,7 +87,7 @@ public class IecServerService { Iterator it = StaticVariable.iecServerMap.keySet().iterator(); while (it.hasNext()) { Integer key = it.next(); - this.onlyStopServer(key); + this.doStopServer(key); } } diff --git a/src/main/java/com/xydl/cac/util/SFTPTool.java b/src/main/java/com/xydl/cac/util/SFTPTool.java index ba6ac97..3ea8a6e 100644 --- a/src/main/java/com/xydl/cac/util/SFTPTool.java +++ b/src/main/java/com/xydl/cac/util/SFTPTool.java @@ -55,7 +55,10 @@ public class SFTPTool { } public void download(String remoteFileName, String localFilePath) throws Exception { - sftp.get(remoteFileName, new FileOutputStream(localFilePath)); + String tmpFile = localFilePath + ".tmp"; + sftp.get(remoteFileName, new FileOutputStream(tmpFile)); + File file = new File(tmpFile); + file.renameTo(new File(localFilePath)); } public void delete(String remoteFileName) throws SftpException {