[问题] FTP传档相关问题

楼主: lesbian5566T (雷斯边五六)   2018-04-30 23:39:55
最近需要开发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();
}
}
作者: zephyrhymn   2018-05-02 15:22:00
给个建议 类似的文章建议附个范例程式 比较会有人回毕竟不是每个人都用过你说的套件 也没多少人会特地帮你模拟出你遇到的问题 最好是附程式码大家比较有回馈
楼主: lesbian5566T (雷斯边五六)   2018-05-05 15:05:00
谢谢, 程式在公司, 下周贴上

Links booklink

Contact Us: admin [ a t ] ucptt.com