我正在使用SFTPClient下载和上传文件。这里的要求是从远程服务器下载时,需要将文件移动到同一服务器的存档文件夹中。我知道,我们可以选择使用以下一个重命名:**
SFTPClient.rename(文件名,目标路径)
. 我尝试过相同的方法,但出现以下异常:**代码:
try {
sftp.lcd(details.get("LOCAL_DIR"));
sftp.cd(details.get("REMOTE_DIR"));
List<SftpFile> remoteFiles = sftp.ls();
for(int i = 0 ; i < remoteFiles.size(); ++i) {
String patternFile = remoteFiles.get(i).getFilename().toUpperCase();
// System.out.println(patternFile);
// System.out.println("Files Format"+patternFile+"***************"+patternFile.matches(details.get("DOWNLOAD_PATTERN")));
if(remoteFiles.get(i).isFile() && patternFile.matches(details.get("DOWNLOAD_PATTERN"))) {
String remoteFile = remoteFiles.get(i).getFilename();
sftp.get(remoteFile);
System.out.println("[SFTPOperations][downLoad] Downloaded: " + remoteFile);
System.out.println("Remote File: " + remoteFile);
System.out.println("Remote Archive Dir: " + details.get("REMOTE_ARCHIVE_DIR"));
sftp.rename(remoteFiles.get(i).getFilename(), details.get("REMOTE_ARCHIVE_DIR"));
System.out.println("[SFTPOperations][downLoad] Archived: " + remoteFile);
}
}
} catch(IOException e) {
System.out.println("[SFTPOperations][downLoad] IOException occurred: " + e.getMessage());
System.out.println("[SFTPOperations][downLoad] Failed to download from " + details.get("REMOTE_DIR"));
e.printStackTrace(System.out);
throw new SFTPException(e.getMessage());
}
例外:
[Jun 04 10:57:58] [SFTPOperations][downLoad] 发生 IOException:失败 [Jun 04 10:57:58] [SFTPOperations][downLoad] 无法从 /home/cordys/CryptoTest/INGInput java.io 下载。 IOException:在 com.sshtools.j2ssh.sftp.SftpSubsystemClient.getOKRequestStatus(未知来源)[Jun 04 10:57:58] 在 com.sshtools.j2ssh.sftp.SftpSubsystemClient.renameFile(未知来源)[Jun 04 10:57:58] at com.sshtools.j2ssh.SftpClient.rename(未知来源)[Jun 04 10:57:58] at com.ing.sftp.SFTPOperations.downLoad(SFTPOperations.java: 82) [Jun 04 10:57:58] at com.ing.schedular.INGCryptoSchedular.downloadEncFiles(INGCryptoSchedular.java:207) [Jun 04 10:57:58] at com.ing.schedular.INGCryptoSchedular.download(INGCryptoSchedular. java:187) [Jun 04 10:57:58] at com.ing.schedular。INGCryptoSchedular.schedule(INGCryptoSchedular.java:83) [Jun 04 10:57:58] at com.ing.schedular.INGCryptoSchedular.main(INGCryptoSchedular.java:294)
请建议如何解决上述问题。