0

I am trying to download some files vis sftp using a java application which uses the sshj library. I am using this tutorial

My code is as follows:

    try {
        sftpClient = client.newSFTPClient();
        remoteFileList = sftpClient.ls("gtdt/xml");
        logger.debug("trying to explicitly donwload file");
        sftpClient.get("remotepath/xml/somefile.xml", new FileSystemFile(localDownloadDir));
    } catch (IOException e) {
        logger.error("Error getting list of remote files on sftp server", e);
        fail("error getting list or remote ftp files");
        
    }

Later I loop over the files that were returned:

    assertTrue(remoteFileList.size() > 0);
    for (RemoteResourceInfo info : remoteFileList) {
        logger.info(info.toString());
    }

but when I try to download any files (have tried one and many) like so

    // get first file in list and download
    RemoteResourceInfo info = remoteFileList.get(0);
    try {
        String localCopyPath = localDownloadDir.getAbsolutePath() + "/" + info.getName();
        FileSystemFile localCopyFile = new FileSystemFile(localDownloadDir.getAbsolutePath() + "/" + info.getName());
        logger.debug("attempting to copy remote file " + info.getPath() + " to : " + localCopyPath);
        sftpClient.get("remotepath/xml/somefile.xml", localCopyFile);
    } catch (IOException e) {
        logger.error("unable to copy file to local dir ", e);
        fail("unable to copy " + info.getName() + " to local dir " + localDownloadDir.getAbsolutePath());
    }
    

I get an error like this:

[main] WARN net.schmizz.sshj.xfer.FileSystemFile - Could not set permissions for c:\mypath\somefile.xml to 1a0

any idea how to fix this? The actual code that is being executed there starts at line 142 here. It wasn't clear to me if this is and issue on my local machine or something I need to configure in sshj.

thanks!

badperson
  • 1,554
  • 3
  • 19
  • 41
  • Does the file(s) get downloaded or not? If yes, then ignore the warning, because the permission being set are for Linux/Unix OS (permissions mask for Read Write and Execute) and Windows does not have them. – pringi Feb 15 '22 at 17:13
  • ok weird...the file did download, but it wasn't before. thanks! – badperson Feb 15 '22 at 18:45

0 Answers0