Tabnine Logo
SFTPEngine
Code IndexAdd Tabnine to your IDE (free)

How to use
SFTPEngine
in
net.schmizz.sshj.sftp

Best Java code snippets using net.schmizz.sshj.sftp.SFTPEngine (Showing top 20 results out of 315)

origin: hierynomus/sshj

public RemoteFile open(String filename, Set<OpenMode> modes)
    throws IOException {
  return open(filename, modes, FileAttributes.EMPTY);
}
origin: hierynomus/sshj

public void makeDir(String path)
    throws IOException {
  makeDir(path, FileAttributes.EMPTY);
}
origin: hierynomus/sshj

public FileAttributes stat(String path)
    throws IOException {
  return engine.stat(path);
}
origin: hierynomus/sshj

/**
 * @return Instantiated {@link SFTPClient} implementation.
 *
 * @throws IOException if there is an error starting the {@code sftp} subsystem
 * @see StatefulSFTPClient
 */
public SFTPClient newSFTPClient()
    throws IOException {
  checkConnected();
  checkAuthenticated();
  return new SFTPClient(new SFTPEngine(this).init());
}
origin: hierynomus/sshj

public PacketReader(SFTPEngine engine) {
  this.engine = engine;
  log = engine.getLoggerFactory().getLogger(getClass());
  this.in = engine.getSubsystem().getInputStream();
  setName("sftp reader");
}
origin: hierynomus/sshj

@Override
public void download(String source, LocalDestFile dest) throws IOException {
  final PathComponents pathComponents = engine.getPathHelper().getComponents(source);
  final FileAttributes attributes = engine.stat(source);
  new Downloader().download(getTransferListener(), new RemoteResourceInfo(pathComponents, attributes), dest);
}
origin: hierynomus/sshj

private LocalDestFile downloadFile(final StreamCopier.Listener listener,
                  final RemoteResourceInfo remote,
                  final LocalDestFile local)
    throws IOException {
  final LocalDestFile adjusted = local.getTargetFile(remote.getName());
  final RemoteFile rf = engine.open(remote.getPath());
  try {
    final RemoteFile.ReadAheadRemoteFileInputStream rfis = rf.new ReadAheadRemoteFileInputStream(16);
    final OutputStream os = adjusted.getOutputStream();
    try {
      new StreamCopier(rfis, os, engine.getLoggerFactory())
          .bufSize(engine.getSubsystem().getLocalMaxPacketSize())
          .keepFlushing(false)
          .listener(listener)
          .copy();
    } finally {
      rfis.close();
      os.close();
    }
  } finally {
    rf.close();
  }
  return adjusted;
}
origin: hierynomus/sshj

SSHClient ssh = fixture.setupConnectedDefaultClient();
ssh.authPassword("test", "test");
SFTPEngine sftp = new SFTPEngine(ssh).init();
rf = sftp.open(file.getPath(), EnumSet.of(OpenMode.WRITE, OpenMode.CREAT));
byte[] data = new byte[8192];
new Random(53).nextBytes(data);
rf = sftp.open(file.getPath());
InputStream rs = rf.new ReadAheadRemoteFileInputStream(16 /*maxUnconfirmedReads*/);
origin: net.schmizz/sshj

private String uploadFile(final StreamCopier.Listener listener,
             final LocalSourceFile local,
             final String remote)
    throws IOException {
  final String adjusted = prepareFile(local, remote);
  final RemoteFile rf = engine.open(adjusted, EnumSet.of(OpenMode.WRITE,
                              OpenMode.CREAT,
                              OpenMode.TRUNC));
  try {
    final InputStream fis = local.getInputStream();
    final RemoteFile.RemoteFileOutputStream rfos = rf.new RemoteFileOutputStream(0, 16);
    try {
      new StreamCopier(fis, rfos)
          .bufSize(engine.getSubsystem().getRemoteMaxPacketSize() - rf.getOutgoingPacketOverhead())
          .keepFlushing(false)
          .listener(listener)
          .copy();
    } finally {
      fis.close();
      rfos.close();
    }
  } finally {
    rf.close();
  }
  return adjusted;
}
origin: hierynomus/sshj

@Before
public void setPathHelper() throws Exception {
  PathHelper helper = new PathHelper(new PathHelper.Canonicalizer() {
    /**
     * Very basic, it does not try to canonicalize relative bits in the middle of a path.
     */
    @Override
    public String canonicalize(String path)
        throws IOException {
      if ("".equals(path) || ".".equals(path) || "./".equals(path))
        return "/home/me";
      if ("..".equals(path) || "../".equals(path))
        return "/home";
      return path;
    }
  }, DEFAULT_PATH_SEPARATOR);
  when(sftpEngine.getPathHelper()).thenReturn(helper);
  when(sftpEngine.stat("/")).thenReturn(new FileAttributes.Builder().withType(FileMode.Type.DIRECTORY).build());
  when(sftpEngine.getLoggerFactory()).thenReturn(LoggerFactory.DEFAULT);
}
origin: hierynomus/sshj

final Response res = requester.request(newRequest(PacketType.READDIR))
    .retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS);
switch (res.getType()) {
      final PathComponents comps = requester.getPathHelper().getComponents(path, name);
      final RemoteResourceInfo inf = new RemoteResourceInfo(comps, attrs);
      if (!(".".equals(name) || "..".equals(name)) && (filter == null || filter.accept(inf))) {
origin: hierynomus/sshj

private boolean makeDirIfNotExists(final String remote) throws IOException {
  try {
    FileAttributes attrs = engine.stat(remote);
    if (attrs.getMode().getType() != FileMode.Type.DIRECTORY) {
      throw new IOException(remote + " exists and should be a directory, but was a " + attrs.getMode().getType());
    }
    // Was not created, but existed.
    return false;
  } catch (SFTPException e) {
    if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) {
      log.debug("makeDir: {} does not exist, creating", remote);
      engine.makeDir(remote);
      return true;
    } else {
      throw e;
    }
  }
}
origin: net.schmizz/sshj

private String prepareDir(final LocalSourceFile local, final String remote)
    throws IOException {
  final FileAttributes attrs;
  try {
    attrs = engine.stat(remote);
  } catch (SFTPException e) {
    if (e.getStatusCode() == StatusCode.NO_SUCH_FILE) {
      log.debug("probeDir: {} does not exist, creating", remote);
      engine.makeDir(remote);
      return remote;
    } else
      throw e;
  }
  if (attrs.getMode().getType() == FileMode.Type.DIRECTORY)
    if (engine.getPathHelper().getComponents(remote).getName().equals(local.getName())) {
      log.debug("probeDir: {} already exists", remote);
      return remote;
    } else {
      log.debug("probeDir: {} already exists, path adjusted for {}", remote, local.getName());
      return prepareDir(local, engine.getPathHelper().adjustForParent(remote, local.getName()));
    }
  else
    throw new IOException(attrs.getMode().getType() + " file already exists at " + remote);
}
origin: iterate-ch/cyberduck

    if(file.isSymbolicLink()) {
      session.sftp().remove(file.getAbsolute());
      flags = EnumSet.of(OpenMode.CREAT, OpenMode.TRUNC, OpenMode.WRITE);
final RemoteFile handle = session.sftp().open(file.getAbsolute(), flags);
final int maxUnconfirmedWrites = this.getMaxUnconfirmedWrites(status);
if(log.isInfoEnabled()) {
origin: hierynomus/sshj

  @Override
  public String canonicalize(String path)
      throws IOException {
    return SFTPEngine.this.canonicalize(path);
  }
}, pathSep);
origin: hierynomus/sshj

private synchronized String cwdify(String path) {
  return engine.getPathHelper().adjustForParent(cwd, path);
}
origin: hierynomus/sshj

public int version() {
  return engine.getOperativeProtocolVersion();
}
origin: iterate-ch/cyberduck

PathAttributes attr;
try {
  final String link = session.sftp().readLink(file.getAbsolute());
  if(link.startsWith(String.valueOf(Path.DELIMITER))) {
    target = new Path(PathNormalizer.normalize(link), EnumSet.of(Path.Type.file));
    final FileAttributes stat = session.sftp().stat(target.getAbsolute());
    if(stat.getType().equals(FileMode.Type.DIRECTORY)) {
      type = Path.Type.directory;
origin: iterate-ch/cyberduck

final FileAttributes stat;
if(file.isSymbolicLink()) {
  stat = session.sftp().lstat(file.getAbsolute());
  stat = session.sftp().stat(file.getAbsolute());
origin: hierynomus/sshj

@Override
public void close()
    throws IOException {
  engine.close();
}
net.schmizz.sshj.sftpSFTPEngine

Most used methods

  • open
  • makeDir
  • stat
  • <init>
  • canonicalize
  • close
  • getOperativeProtocolVersion
  • getPathHelper
  • getSubsystem
  • init
  • lstat
  • openDir
  • lstat,
  • openDir,
  • readLink,
  • remove,
  • removeDir,
  • rename,
  • request,
  • setAttributes,
  • symlink,
  • doRequest

Popular in Java

  • Running tasks concurrently on multiple threads
  • putExtra (Intent)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Collectors (java.util.stream)
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now