【发布时间】:2019-02-26 11:10:45
【问题描述】:
我已经尝试了所有可能的方法来将一些内容附加到 SFTP 文件路径中存在的文件中。我收到了成功消息,但找不到更新的文件。 不知道是什么原因。
请在下面找到我的代码:
jsch = new JSch();
jsch.addIdentity(privateKey);
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password");
ProxyHTTP proxy = new ProxyHTTP(PROXY, 8080);
session.setProxy(proxy);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("cipher.s2c", "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,aes256-ctr");
session.setConfig("cipher.c2s", "aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,aes256-ctr");
session.connect();
sftpChannel = (ChannelSftp)session.openChannel("sftp");
sftpChannel.connect();
if(sftpChannel.getSession().isConnected())
logger.debug("Remote session established through the channel");
sftpChannel.cd(remoteDirectory);
List<String> list = new ArrayList<>();
ChannelSftp sftp = (ChannelSftp) sftpChannel;
Vector<LsEntry> files = sftp.ls(remoteDirectory);
for (LsEntry entry : files)
{
if (!entry.getFilename().equals(".") && !entry.getFilename().equals(".."))
{
list.add(entry.getFilename());
}
}
System.out.println(list);
InputStream stream = sftp.get(remoteDirectory + remoteFile);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
// read from br
} finally {
stream.close();
}
Files.write(Paths.get(remoteFile), "CH|OK|en,ch,de,it|CH ".getBytes(), StandardOpenOption.APPEND);
System.out.println("added country to remote path");
sftpChannel.exit();
session.disconnect();
【问题讨论】: