如何使用SFTP重命名文件时解决IOException?

时间:2013-06-04 05:36:08

标签: java file sftp

我正在使用 SFTPClient 下载上传文件。这里的要求是从远程服务器下载时,需要将文件移动到同一服务器的归档文件夹中。 我知道,我们可以选择使用以下方式重命名 - :**

  

SFTPClient.rename(文件名,的DestinationPath)

即可。 我尝试过相同但我得到以下异常: **代码:

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下载:   失败[Jun 04 10:57:58] at   com.sshtools.j2ssh.sftp.SftpSubsystemClient.getOKRequestStatus(未知   来源)[Jun 04 10:57:58] at   com.sshtools.j2ssh.sftp.SftpSubsystemClient.renameFile(未知来源)   [Jun 04 10:57:58] at com.sshtools.j2ssh.SftpClient.rename(Unknown   来源)[Jun 04 10:57:58] at   com.ing.sftp.SFTPOperations.downLoad(SFTPOperations.java:82)[Jun 04   10:57:58]   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)

请建议如何解决上述问题。

0 个答案:

没有答案