net.schmizz.sshj.sftp.FileMode Java Examples

The following examples show how to use net.schmizz.sshj.sftp.FileMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SFTPRemoteDownloadSourceDelegate.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void queueFiles(FileQueueChecker fqc, NavigableSet<RemoteFile> fileQueue, FileFilter fileFilter, String remoteDirPath)
    throws IOException {
  List<ChrootSFTPClient.SimplifiedRemoteResourceInfo> theFiles = (remoteDirPath == null)
    ? sftpClient.ls(fileFilter)
    : sftpClient.ls(remoteDirPath, fileFilter);

  for (ChrootSFTPClient.SimplifiedRemoteResourceInfo remoteFileInfo : theFiles) {
    LOG.debug("Checking {}", remoteFileInfo.getPath());
    if (conf.processSubDirectories && remoteFileInfo.getType() == FileMode.Type.DIRECTORY) {
      queueFiles(fqc, fileQueue, fileFilter, remoteFileInfo.getPath());
      continue;
    }

    if (remoteFileInfo.getType() != FileMode.Type.REGULAR) {
      LOG.trace("Skipping {} because it is not a file", remoteFileInfo.getPath());
      continue;
    }

    RemoteFile tempFile = new SFTPRemoteFile(
        slashify(remoteFileInfo.getPath()),
        convertSecsToMillis(remoteFileInfo.getModifiedTime()),
        sftpClient);
    if (fqc.shouldQueue(tempFile)) {
      LOG.debug("Queuing file {} with modtime {}", tempFile.getFilePath(), tempFile.getLastModified());
      // If we are done with all files, the files with the final mtime might get re-ingested over and over.
      // So if it is the one of those, don't pull it in.
      fileQueue.add(tempFile);
    }
  }
}
 
Example #2
Source File: ChrootSFTPClient.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public SimplifiedRemoteResourceInfo(String path, long modifiedTime, FileMode.Type type) {
  this.path = path;
  this.modifiedTime = modifiedTime;
  this.type = type;
}
 
Example #3
Source File: ChrootSFTPClient.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public FileMode.Type getType() {
  return type;
}
 
Example #4
Source File: TestChrootSFTPClient.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Test
public void testLs() throws Exception {
  File fileInRoot = testFolder.newFile("fileInRoot.txt");
  File dirInRoot = testFolder.newFolder("dirInRoot");
  File fileInDirInRoot = new File(dirInRoot, "fileInDirInRoot.txt");
  Files.touch(fileInDirInRoot);

  path = testFolder.getRoot().getAbsolutePath();
  setupSSHD(path);
  SSHClient sshClient = createSSHClient();

  /**
   * ...
   * ├── path (root)
   * │   ├─── fileInRoot.txt
   * │   ├─── dirInRoot
   * │   │    └── fileInDirInRoot.txt
   */

  for (ChrootSFTPClient sftpClient : getClientsWithEquivalentRoots(sshClient)) {
    List<ChrootSFTPClient.SimplifiedRemoteResourceInfo> files = sftpClient.ls();
    Assert.assertEquals(2, files.size());
    for (ChrootSFTPClient.SimplifiedRemoteResourceInfo file : files) {
      if (file.getType() == FileMode.Type.REGULAR) {
        Assert.assertEquals("/" + fileInRoot.getName(), file.getPath());
      } else {  // dir
        Assert.assertEquals("/" + dirInRoot.getName(), file.getPath());
      }
    }
    // We can specify a dir as either a relative path "dirInRoot" or an absolute path "/dirInRoot" and they should be
    // equivalent
    for (String p : new String[] {
        dirInRoot.getName(),
        "/" + dirInRoot.getName(),
    })
    files = sftpClient.ls(p);
    Assert.assertEquals(1, files.size());
    Assert.assertEquals("/" + dirInRoot.getName() + "/" + fileInDirInRoot.getName(),
        files.iterator().next().getPath());
  }
}