Ver código fonte

生成文件测试

zhouger 7 meses atrás
pai
commit
56407ac064
1 arquivos alterados com 12 adições e 9 exclusões
  1. 12 9
      src/main/java/sys/sc/formplugin/CreatDatPlugin.java

+ 12 - 9
src/main/java/sys/sc/formplugin/CreatDatPlugin.java

@@ -96,12 +96,15 @@ public class CreatDatPlugin extends AbstractListPlugin {
             SftpClient sftpClient=new SftpClient(host,username,password,port);
             try {
                 //临时文件
-                Path localFile = Files.createTempFile(tablenumber, ".dat");
-                //文件生成到本地路径
-                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,localFile.toString(),spiltsign,endsign);
+                File localFile = File.createTempFile(tablenumber, ".dat");
+                //文件写入
+                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,localFile.getAbsolutePath(),spiltsign,endsign);
                 //生成dat文件到本地
                 datFileCreatUtils.creatDatFile();
-                sftpClient.fileCreat(String.valueOf(localFile),nckd_url);
+                //从本地传文件到服务器
+                sftpClient.fileCreat(localFile.getAbsolutePath(), nckd_url);
+                //上传后删除临时文件
+                localFile.delete();
             } catch (IOException e) {
                 throw new RuntimeException(e);
             } catch (SftpException e) {
@@ -117,11 +120,11 @@ public class CreatDatPlugin extends AbstractListPlugin {
 //            SftpClient sftpClient=new SftpClient("192.168.10.69","root","Kd@86262007",22);
 //
 //            try {
-////                sftpClient.connect();
-////                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,filePath,spiltsign,endsign);
-////                Files.write(localFile, Collections.singleton("Hello, SFTP!"));
-////                sftpClient.fileCreat(localFile.toString(),remoteFilePath);  // 清理临时文件
-////                Files.delete(localFile);
+//                sftpClient.connect();
+//                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,filePath,spiltsign,endsign);
+//                Files.write(localFile, Collections.singleton("Hello, SFTP!"));
+//                sftpClient.fileCreat(localFile.toString(),remoteFilePath);  // 清理临时文件
+//                Files.delete(localFile);
 //            } catch (IOException e) {
 //                throw new RuntimeException(e);
 //            } catch (Exception e) {