[問題] FTP傳檔相關問題

看板java作者 (雷斯邊五六)時間6年前 (2018/04/30 23:39), 6年前編輯推噓1(103)
留言4則, 2人參與, 6年前最新討論串1/1
最近需要開發FTP功能, 使用Jsch. 問題一: 其中一個功能為抓取固定路徑下的所有檔案, 一個一個透過SFTP丟到Web applinacion, 跑迴圈, 每put一個檔案就呼叫file.delete(), 檔案可以正確傳過去, 但是資料夾內的檔案卻不會被刪除, 看log也沒有exception, 是因為java執行到delete時, outputStream還沒關閉嗎? 但卻不會丟錯? 問題二: FTP功能是透過web application執行, 而檔案禁止放在web server內, 所以FTP的取檔功能目前想法是一次讀取完放記憶體, 開放inputStream拿檔. 但jsch提供的功能似乎只有inputStream, 請問要如何在web server內既不create File又能全部讀完串流? 因為檔案被管制能碰到的人有限, 所以先不用考慮同步問題. 問題三: 另外請教, 在一個執行中的web application, SFTP去replace .class跟.html, 來更新程式碼, 會有任何後遺症嗎? 目前不多人用, 系統看起來沒有出什麼奇怪的錯. 感覺是server偵測到.class修改時間有變化, 會load最新版本class進記憶體? 程式如下: JSch jsch = new JSch(); Session sshSession = jsch.getSession(userName, ip, port); Channel channel; try { sshSession.setPassword(PASSWORD); java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); config.put("PreferredAuthentications", "password"); sshSession.setConfig(config); sshSession.setTimeout(5000); sshSession.connect(); channel = sshSession.openChannel("sftp"); channel.connect(); ChannelSftp sftp = null; sftp = (ChannelSftp) channel; StringBuilder sb = new StringBuilder(); for (File f$ : new File(SOURCE_PATH).listFiles()) { if(f$.isDirectory()){ continue; } String aixPath = getRemoteFilePath(f$, sb); if ("".equals(aixPath)) { continue; } sftp.put(new FileInputStream(f$), aixPath); System.err.println(ip+":"+f$.getName()); f$.delete(); } channel.disconnect(); sshSession.disconnect(); } finally { if (sshSession.isConnected()) { sshSession.disconnect(); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.160.21 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1525102797.A.C0C.html

05/02 15:22, 6年前 , 1F
給個建議 類似的文章建議附個範例程式 比較會有人回
05/02 15:22, 1F

05/02 15:23, 6年前 , 2F
畢竟不是每個人都用過你說的套件 也沒多少人會特地幫
05/02 15:23, 2F

05/02 15:24, 6年前 , 3F
你模擬出你遇到的問題 最好是附程式碼大家比較有回饋
05/02 15:24, 3F

05/05 15:05, 6年前 , 4F
謝謝, 程式在公司, 下周貼上
05/05 15:05, 4F
※ 編輯: lesbian5566T (61.230.172.207), 05/09/2018 21:53:40 ※ 編輯: lesbian5566T (61.230.172.207), 05/09/2018 21:54:11
文章代碼(AID): #1QvpZDmC (java)