private void setPermissions(String path, int permissions) throws SftpException { if (permissions > -1) { SftpATTRS attrs = channel.stat(path); attrs.setPERMISSIONS(permissions); channel.setStat(path, attrs); } }
private void flushStat() throws IOException, SftpException { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.setStat(relPath, attrs); } finally { getAbstractFileSystem().putChannel(channel); } }
private void flushStat() throws IOException, SftpException { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.setStat(relPath, attrs); } finally { getAbstractFileSystem().putChannel(channel); } }
private void flushStat() throws IOException, SftpException { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.setStat(relPath, attrs); } finally { getAbstractFileSystem().putChannel(channel); } }
private void flushStat() throws IOException, SftpException { final ChannelSftp channel = getAbstractFileSystem().getChannel(); try { channel.setStat(relPath, attrs); } finally { getAbstractFileSystem().putChannel(channel); } }
@Override public void setMode(int mode) throws IOException { SftpATTRS stat; ChannelSftp sftp; try { sftp = alloc(); try { stat = sftp.stat(escape(slashPath)); stat.setPERMISSIONS(mode); sftp.setStat(escape(slashPath), stat); } finally { free(sftp); } } catch (SftpException e) { throw new IOException(e); } catch (JSchException e) { throw new IOException(e); } }
public void chown(String path, int uid) throws SshException { try { SftpATTRS attrs = channel.stat(path); attrs.setUIDGID(uid, attrs.getGId()); channel.setStat(path, attrs); } catch (SftpException e) { throw new net.sf.sshapi.sftp.SftpException(e.id, e.getLocalizedMessage(), e); } }
public void chgrp(String path, int gid) throws SshException { try { SftpATTRS attrs = channel.stat(path); attrs.setUIDGID(attrs.getUId(), gid); channel.setStat(path, attrs); } catch (SftpException e) { throw new net.sf.sshapi.sftp.SftpException(e.id, e.getLocalizedMessage(), e); } }
public void setLastModified(String path, long modtime) throws SshException { try { SftpATTRS attrs = channel.stat(path); attrs.setACMODTIME((int) attrs.getMTime(), (int) modtime / 1000); channel.setStat(path, attrs); } catch (SftpException e) { throw new net.sf.sshapi.sftp.SftpException(e.id, e.getLocalizedMessage(), e); } }
@Override public void setGid(int gid) throws IOException { String str; SftpATTRS stat; ChannelSftp sftp; try { if (isDirectory()) { // TODO str = getRoot().exec("chgrp", Integer.toString(gid), slashPath); if (str.length() > 0) { throw new IOException("chgrp failed:" + str); } } else { sftp = alloc(); try { stat = sftp.stat(escape(slashPath)); stat.setUIDGID(stat.getUId(), gid); sftp.setStat(escape(slashPath), stat); } finally { free(sftp); } } } catch (JSchException e) { throw new IOException(e); } catch (SftpException e) { throw new IOException(e); } }
/** * Sets the last modified time of this file. Is only called if * {@link #doGetType} does not return {@link FileType#IMAGINARY}. <p/> * * @param modtime * is modification time in milliseconds. SFTP protocol can send * times with nanosecond precision but at the moment jsch send * them with second precision. */ protected void doSetLastModifiedTime(final long modtime) throws Exception { final ChannelSftp channel = fileSystem.getChannel(); try { int newMTime = (int) (modtime / 1000L); attrs.setACMODTIME(attrs.getATime(), newMTime); channel.setStat(relPath, attrs); } finally { fileSystem.putChannel(channel); } }
@Override public void setUid(int uid) throws IOException { String str; SftpATTRS stat; ChannelSftp sftp; try { if (isDirectory()) { // TODO str = getRoot().exec("chown", Integer.toString(uid), escape(slashPath)); if (str.length() > 0) { throw new IOException("chown failed:" + str); } } else { sftp = alloc(); try { stat = sftp.stat(escape(slashPath)); stat.setUIDGID(uid, stat.getGId()); sftp.setStat(escape(slashPath), stat); } finally { free(sftp); } } } catch (JSchException e) { throw new IOException(e); } catch (SftpException e) { throw new IOException(e); } }
@Override public void setPermissions(String permissions) throws ModeException { SftpATTRS stat; ChannelSftp sftp; try { sftp = alloc(); try { stat = sftp.stat(escape(slashPath)); stat.setPERMISSIONS(fromPermissions(permissions)); sftp.setStat(escape(slashPath), stat); } finally { free(sftp); } } catch (SftpException | JSchException e) { throw new ModeException(this, e); } }
@Override public void changeDate(long lastModified) throws IOException, UnsupportedFileOperationException { SFTPConnectionHandler connHandler = null; SftpATTRS attributes = null; try { // Retrieve a ConnectionHandler and lock it connHandler = (SFTPConnectionHandler)ConnectionPool.getConnectionHandler(connHandlerFactory, fileURL, true); // Makes sure the connection is started, if not starts it connHandler.checkConnection(); // Retrieve an SftpFile instance for write, will throw an IOException if the file does not exist or cannot // be written. // /!\ SftpFile instance must be closed afterwards to release its file handle attributes = connHandler.channelSftp.lstat(absPath); attributes.setACMODTIME(attributes.getATime(), (int)(lastModified/1000)); connHandler.channelSftp.setStat(absPath, attributes); // Update local attribute copy fileAttributes.setDate(lastModified); } catch (SftpException e) { e.printStackTrace(); } finally { // Release the lock on the ConnectionHandler if(connHandler!=null) connHandler.releaseLock(); } }
@Override public void setGroup(GroupPrincipal group) throws ModeException { String str; SftpATTRS stat; ChannelSftp sftp; try { if (isDirectory()) { // TODO str = getRoot().exec("chgrp", group.getName(), slashPath); if (str.length() > 0) { throw new ModeException(this, "chgrp failed:" + str); } } else { sftp = alloc(); try { stat = sftp.stat(escape(slashPath)); stat.setUIDGID(stat.getUId(), ((SshPrincipal) group).id); sftp.setStat(escape(slashPath), stat); } finally { free(sftp); } } } catch (NodeException | ExitCode | JSchException | SftpException e) { throw new ModeException(this, e); } }
@Override public void setOwner(UserPrincipal owner) throws ModeException { String str; SftpATTRS stat; ChannelSftp sftp; try { if (isDirectory()) { // TODO str = getRoot().exec("chown", owner.getName(), escape(slashPath)); if (str.length() > 0) { throw new ModeException(this, "chown failed:" + str); } } else { sftp = alloc(); try { stat = sftp.stat(escape(slashPath)); stat.setUIDGID(((SshPrincipal) owner).id, stat.getGId()); sftp.setStat(escape(slashPath), stat); } finally { free(sftp); } } } catch (ExitCode | NodeException | JSchException | SftpException e) { throw new ModeException(this, e); } }