@Override public void put(String source, String dest) throws IOException { super.put(source, cwdify(dest)); }
@Override public void setattr(String path, FileAttributes attrs) throws IOException { super.setattr(cwdify(path), attrs); }
@Test public void doesNotTryToCreateDirectoryTwiceWhenPathHasTrailingSeparator() throws Exception { SFTPClient client = new SFTPClient(sftpEngine); client.mkdirs("/folder/directory/"); verify(sftpEngine, times(1)).makeDir("/folder/directory"); } }
@Override public void clear() throws IOException { if (sftp != null) sftp.close(); }
sftp = acquire(sftpConnection); try { sftp.put(new InMemorySourceFile() { @Override public String getName() { return path; sftp.chmod(path, permissionsMask); if (uid != -1) { sftp.chown(path, uid); sftp.setattr(path, new FileAttributes.Builder() .withAtimeMtime(lastAccessDate, lastModificationDate) .build());
@Override public Void create() throws Exception { final AtomicReference<InputStream> inputStreamRef = new AtomicReference<InputStream>(); sftp = acquire(sftpConnection); try { sftp.put(new InMemorySourceFile() { @Override public String getName() { return path; } @Override public long getLength() { return length; } @Override public InputStream getInputStream() throws IOException { InputStream contents = contentsSupplier.get(); inputStreamRef.set(contents); return contents; } }, path); sftp.chmod(path, permissionsMask); if (lastAccessDate > 0) { sftp.setattr(path, new FileAttributes.Builder() .withAtimeMtime(lastAccessDate, lastModificationDate) .build()); } } finally { closeWhispering(inputStreamRef.get(), this); } return null; }
@Override public InputStream create() throws Exception { sftp = acquire(sftpConnection); return new CloseFtpChannelOnCloseInputStream( sftp.getSFTPEngine().open(path).getInputStream(), sftp); }
public void mkdirs(String path) throws IOException { final Deque<String> dirsToMake = new LinkedList<String>(); for (PathComponents current = engine.getPathHelper().getComponents(path); ; current = engine.getPathHelper().getComponents(current.getParent())) { final FileAttributes attrs = statExistence(current.getPath()); if (attrs == null) { dirsToMake.push(current.getPath()); } else if (attrs.getType() != FileMode.Type.DIRECTORY) { throw new SFTPException(current.getPath() + " exists but is not a directory"); } else { break; } } while (!dirsToMake.isEmpty()) { mkdir(dirsToMake.pop()); } }
@Override public void get(String source, String dest) throws IOException { super.get(cwdify(source), dest); }
@Test public void shouldExecuteBackgroundCommand() throws IOException { SSHClient sshClient = fixture.setupConnectedDefaultClient(); sshClient.authPassword("jeroen", "jeroen"); File file = new File(temp.getRoot(), "testdir"); assertThat("File should not exist", !file.exists()); // TODO figure out why this does not really execute in the background. Session.Command exec = sshClient.startSession().exec("mkdir " + file.getPath() + " &"); exec.join(); assertThat("File should exist", file.exists()); assertThat("File should be directory", file.isDirectory()); SFTPClient sftpClient = sshClient.newSFTPClient(); if (sftpClient.statExistence("&") != null) { sftpClient.rmdir("&"); // TODO fail here when this is fixed } } }
@Override public void mkdirs(String path) throws IOException { super.mkdirs(cwdify(path)); }
/** * @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()); }
@Override public void rmdir(String dirname) throws IOException { super.rmdir(cwdify(dirname)); }
@Override public FileAttributes statExistence(String path) throws IOException { return super.statExistence(cwdify(path)); }
@Override public void clear() throws IOException { if (sftp != null) sftp.close(); }
@Override public Payload create() throws Exception { sftp = acquire(sftpConnection); final RemoteFile remoteFile = sftp.getSFTPEngine().open(path); final InputStream in = remoteFile.new RemoteFileInputStream() { @Override public void close() throws IOException { try { super.close(); } finally { remoteFile.close(); } } }; return Payloads.newInputStreamPayload(new CloseFtpChannelOnCloseInputStream(in, sftp)); }