@Override public boolean mkdirs(Path path, FsPermission permission) throws IOException { ChannelSftp channel = null; try { channel = this.fsHelper.getSftpChannel(); channel.mkdir(HadoopUtils.toUriPath(path)); channel.chmod(permission.toShort(), HadoopUtils.toUriPath(path)); } catch (SftpException e) { throw new IOException(e); } finally { safeDisconnect(channel); } return true; }
int perms = numberPermissions(permissions); if (perms >= 0) { sftp.chmod(perms, tempPath);
@Override protected void doChmod(RemoteFileTemplate<LsEntry> remoteFileTemplate, final String path, final int chmod) { remoteFileTemplate.executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> { try { client.chmod(chmod, path); } catch (SftpException e) { throw new GeneralSftpException("Failed to execute chmod", e); } }); }
@Override protected void doChmod(RemoteFileOperations<LsEntry> remoteFileOperations, final String path, final int chmod) { remoteFileOperations .executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> { try { client.chmod(chmod, path); } catch (SftpException e) { throw new GeneralSftpException("Failed to execute chmod", e); } }); }
@Test public void testInt3088MPutNotRecursive() throws Exception { Session<?> session = sessionFactory.getSession(); session.close(); session = TestUtils.getPropertyValue(session, "targetSession", Session.class); ChannelSftp channel = spy(TestUtils.getPropertyValue(session, "channel", ChannelSftp.class)); new DirectFieldAccessor(session).setPropertyValue("channel", channel); String dir = "sftpSource/"; this.inboundMGetRecursive.send(new GenericMessage<Object>(dir + "*")); while (output.receive(0) != null) { // drain } this.inboundMPut.send(new GenericMessage<File>(getSourceLocalDirectory())); @SuppressWarnings("unchecked") Message<List<String>> out = (Message<List<String>>) this.output.receive(1000); assertNotNull(out); assertEquals(2, out.getPayload().size()); assertThat(out.getPayload().get(0), not(equalTo(out.getPayload().get(1)))); assertThat( out.getPayload().get(0), anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"))); assertThat( out.getPayload().get(1), anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt"))); verify(channel).chmod(384, "sftpTarget/localSource1.txt"); // 384 = 600 octal verify(channel).chmod(384, "sftpTarget/localSource2.txt"); }
void chmod(String path, int permissions) throws IOException { try { channel.chmod(permissions, path); } catch (SftpException e) { throw exceptionFactory.createSetPermissionsException(path, e); } }
public void chmod(String path, int permissions) throws SftpException { path = normalizePath(path); sftpChannel.chmod(permissions, path); }
@Override protected void doChmod(RemoteFileOperations<LsEntry> remoteFileOperations, final String path, final int chmod) { remoteFileOperations .executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> { try { client.chmod(chmod, path); } catch (SftpException e) { throw new GeneralSftpException("Failed to execute chmod", e); } }); }
@Override protected void doChmod(RemoteFileTemplate<LsEntry> remoteFileTemplate, final String path, final int chmod) { remoteFileTemplate.executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> { try { client.chmod(chmod, path); } catch (SftpException e) { throw new GeneralSftpException("Failed to execute chmod", e); } }); }
public void uploadFile(InputStream stream, String path, int mode) throws JSchException, SftpException { Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp channelSftp = (ChannelSftp) channel; channelSftp.put(stream, path); channelSftp.chmod(mode, path); channelSftp.exit(); }
@Override public synchronized boolean setPermissions(int permissions, String path) throws RemoteException { try { sftpLogger.info(String.format("chmod %d %s", permissions, path)); // NOI18N sftpClient.chmod(permissions, path); sftpLogger.info(NbBundle.getMessage(SftpClient.class, "LOG_ChmodOk")); return true; } catch (SftpException ex) { LOGGER.log(Level.FINE, "Error while setting permissions for " + path, ex); sftpLogger.error(ex.getLocalizedMessage()); return false; } }
/** * Makes sure that the directory exists, by creating it if necessary. */ public void mkdirs(String path, int posixPermission) throws SftpException { // remove trailing slash if present if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } path = normalizePath(path); SftpATTRS attrs = _stat(path); if (attrs != null && attrs.isDir()) return; int idx = path.lastIndexOf("/"); if (idx>0) mkdirs(path.substring(0,idx), posixPermission); sftpChannel.mkdir(path); sftpChannel.chmod(posixPermission, path); }
protected void setAttributes(RemoteFile file) throws SftpException { String path = file.getAbsolutePath(); if (file.getPermissions().isPresent()) { sftp.chmod(file.getPermissions().get(), path); } if (file.getGroupId().isPresent()) { sftp.chgrp(file.getGroupId().get(), path); } if (file.getUserId().isPresent()) { sftp.chown(file.getUserId().get(), path); } }
protected void setAttributes(RemoteFile file) throws SftpException { String path = file.getAbsolutePath(); if (file.getPermissions().isPresent()) { sftp.chmod(file.getPermissions().get(), path); } if (file.getGroupId().isPresent()) { sftp.chgrp(file.getGroupId().get(), path); } if (file.getUserId().isPresent()) { sftp.chown(file.getUserId().get(), path); } }
@Override public boolean mkdirs(Path path, FsPermission permission) throws IOException { ChannelSftp channel = null; try { channel = this.fsHelper.getSftpChannel(); channel.mkdir(HadoopUtils.toUriPath(path)); channel.chmod(permission.toShort(), HadoopUtils.toUriPath(path)); } catch (SftpException e) { throw new IOException(e); } finally { safeDisconnect(channel); } return true; }
private void setFileMode( String filename, RepositoryPermissions permissions ) { try { int mode = getOctalMode( permissions.getFileMode() ); channel.chmod( mode, filename ); } catch ( NumberFormatException e ) { // TODO: warning level fireTransferDebug( "Not setting mode: must be a numerical mode for SFTP" ); } catch ( SftpException e ) { fireTransferDebug( "Not setting mode: " + e.getMessage() ); } }
private void sendDirectoryToRemote(final ChannelSftp channel, final Directory directory) throws IOException, SftpException { final String dir = directory.getDirectory().getName(); try { channel.stat(dir); } catch (final SftpException e) { // dir does not exist. if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { channel.mkdir(dir); channel.chmod(getDirMode(), dir); } } channel.cd(dir); sendDirectory(channel, directory); channel.cd(".."); }
private void setFileMode( String filename, RepositoryPermissions permissions ) { try { int mode = getOctalMode( permissions.getFileMode() ); channel.chmod( mode, filename ); } catch ( NumberFormatException e ) { // TODO: warning level fireTransferDebug( "Not setting mode: must be a numerical mode for SFTP" ); } catch ( SftpException e ) { fireTransferDebug( "Not setting mode: " + e.getMessage() ); } }
@Override protected boolean doSetPermissions(int mask) throws Exception { if (attrs == null) { throw new FileSystemException("vfs.provider/get-type.error"); } final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.chmod(mask, relPath); attrs.setPERMISSIONS(mask); // if chmod succeeded we just need to update attrs return true; } finally { getAbstractFileSystem().putChannel(channel); } }
protected void setAttributes(RemoteFile file) throws SftpException { String path = file.getAbsolutePath(); if (file.getPermissions() != null) { sftp.chmod(file.getPermissions(), path); } if (file.getGroupId() != null) { sftp.chgrp(file.getGroupId(), path); } if (file.getUserId() != null) { sftp.chown(file.getUserId(), path); } }