long accessTime = attr.getATime() * 1000L; FsPermission permission = getPermissions(sftpFile);
@Override public FileStatus getFileStatus(Path path) throws IOException { ChannelSftp channelSftp = null; ChannelExec channelExec1 = null; ChannelExec channelExec2 = null; try { channelSftp = this.fsHelper.getSftpChannel(); SftpATTRS sftpAttrs = channelSftp.stat(HadoopUtils.toUriPath(path)); FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions()); channelExec1 = this.fsHelper.getExecChannel("id " + sftpAttrs.getUId()); String userName = IOUtils.toString(channelExec1.getInputStream()); channelExec2 = this.fsHelper.getExecChannel("id " + sftpAttrs.getGId()); String groupName = IOUtils.toString(channelExec2.getInputStream()); FileStatus fs = new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, sftpAttrs.getMTime(), sftpAttrs.getATime(), permission, StringUtils.trimToEmpty(userName), StringUtils.trimToEmpty(groupName), path); return fs; } catch (SftpException e) { throw new IOException(e); } finally { safeDisconnect(channelSftp); safeDisconnect(channelExec1); safeDisconnect(channelExec2); } }
@Override public FileAbstractModel toFileAbstractModel(String path, ChannelSftp.LsEntry file) { return new FileAbstractModel( file.getFilename(), file.getAttrs().isDir(), // We are using here the local TimeZone as a reference. If the remote system is under another TZ, this might cause issues LocalDateTime.ofInstant(Instant.ofEpochMilli(file.getAttrs().getMTime()*1000L), ZoneId.systemDefault()), // We don't have the creation date null, // We are using here the local TimeZone as a reference. If the remote system is under another TZ, this might cause issues LocalDateTime.ofInstant(Instant.ofEpochMilli(file.getAttrs().getATime()*1000L), ZoneId.systemDefault()), FilenameUtils.getExtension(file.getFilename()), path, path.concat("/").concat(file.getFilename()), file.getAttrs().getSize(), Integer.toString(file.getAttrs().getUId()), Integer.toString(file.getAttrs().getGId()), file.getAttrs().getPermissions()); }
@Override public FileTime lastAccessTime() { // times are in seconds return FileTime.from(attributes.getATime(), TimeUnit.SECONDS); }
@Override public FileTime lastAccessTime() { return FileTime.fromMillis(attrs.getATime()*1000L); }
/** * Sets the last modified time of this file. Is only called if {@link #doGetType} does not return * {@link FileType#IMAGINARY}. * * @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. */ @Override protected boolean doSetLastModifiedTime(final long modtime) throws Exception { final int newMTime = (int) (modtime / MOD_TIME_FACTOR); attrs.setACMODTIME(attrs.getATime(), newMTime); flushStat(); return true; }
/** * Sets the last modified time of this file. Is only called if {@link #doGetType} does not return * {@link FileType#IMAGINARY}. * * @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. */ @Override protected boolean doSetLastModifiedTime(final long modtime) throws Exception { final int newMTime = (int) (modtime / MOD_TIME_FACTOR); attrs.setACMODTIME(attrs.getATime(), newMTime); flushStat(); return true; }
/** * Sets the last modified time of this file. Is only called if {@link #doGetType} does not return * {@link FileType#IMAGINARY}. * * @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. */ @Override protected boolean doSetLastModifiedTime(final long modtime) throws Exception { final int newMTime = (int) (modtime / MOD_TIME_FACTOR); attrs.setACMODTIME(attrs.getATime(), newMTime); flushStat(); return true; }
/** * Sets the last modified time of this file. Is only called if * {@link #doGetType} does not return {@link FileType#IMAGINARY}. * * @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. */ @Override protected boolean doSetLastModifiedTime(final long modtime) throws Exception { final int newMTime = (int) (modtime / MOD_TIME_FACTOR); attrs.setACMODTIME(attrs.getATime(), newMTime); flushStat(); return true; }
/** * 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); } }
public void setMtime(String path, int mtime) throws SftpException{ try{ path=remoteAbsolutePath(path); Vector v=glob_remote(path); int vsize=v.size(); for(int j=0; j<vsize; j++){ path=(String)(v.elementAt(j)); SftpATTRS attr=_stat(path); attr.setFLAGS(0); attr.setACMODTIME(attr.getATime(), mtime); _setStat(path, attr); } } catch(Exception e){ if(e instanceof SftpException) throw (SftpException)e; if(e instanceof Throwable) throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e); throw new SftpException(SSH_FX_FAILURE, ""); } }
public SftpFile[] ls(String path) throws SshException { Vector paths; try { paths = channel.ls(path); } catch (SftpException e) { throw new net.sf.sshapi.sftp.SftpException(e.id, e.getLocalizedMessage(), e); } List files = new ArrayList(); for (Enumeration e = paths.elements(); e.hasMoreElements();) { ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) e.nextElement(); SftpFile file = new SftpFile(convertType(entry.getAttrs()), entry.getFilename(), entry.getAttrs().getSize(), convertIntDate(entry.getAttrs().getMTime()), 0, convertIntDate(entry.getAttrs().getATime()), entry.getAttrs() .getGId(), entry.getAttrs().getUId(), entry.getAttrs().getPermissions()); files.add(file); } return (SftpFile[]) files.toArray(new SftpFile[paths.size()]); }
public void setMtime(String path, int mtime) throws SftpException{ try{ ((MyPipedInputStream)io_in).updateReadSide(); path=remoteAbsolutePath(path); Vector v=glob_remote(path); int vsize=v.size(); for(int j=0; j<vsize; j++){ path=(String)(v.elementAt(j)); SftpATTRS attr=_stat(path); attr.setFLAGS(0); attr.setACMODTIME(attr.getATime(), mtime); _setStat(path, attr); } } catch(Exception e){ if(e instanceof SftpException) throw (SftpException)e; if(e instanceof Throwable) throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e); throw new SftpException(SSH_FX_FAILURE, ""); } }
public void setMtime(String path, int mtime) throws SftpException{ try{ ((MyPipedInputStream)io_in).updateReadSide(); path=remoteAbsolutePath(path); Vector v=glob_remote(path); int vsize=v.size(); for(int j=0; j<vsize; j++){ path=(String)(v.elementAt(j)); SftpATTRS attr=_stat(path); attr.setFLAGS(0); attr.setACMODTIME(attr.getATime(), mtime); _setStat(path, attr); } } catch(Exception e){ if(e instanceof SftpException) throw (SftpException)e; if(e instanceof Throwable) throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e); throw new SftpException(SSH_FX_FAILURE, ""); } }
@Override public FileStatus getFileStatus(Path path) throws IOException { ChannelSftp channelSftp = null; ChannelExec channelExec1 = null; ChannelExec channelExec2 = null; try { channelSftp = this.fsHelper.getSftpChannel(); SftpATTRS sftpAttrs = channelSftp.stat(HadoopUtils.toUriPath(path)); FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions()); channelExec1 = this.fsHelper.getExecChannel("id " + sftpAttrs.getUId()); String userName = IOUtils.toString(channelExec1.getInputStream()); channelExec2 = this.fsHelper.getExecChannel("id " + sftpAttrs.getGId()); String groupName = IOUtils.toString(channelExec2.getInputStream()); FileStatus fs = new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, sftpAttrs.getMTime(), sftpAttrs.getATime(), permission, StringUtils.trimToEmpty(userName), StringUtils.trimToEmpty(groupName), path); return fs; } catch (SftpException e) { throw new IOException(e); } finally { safeDisconnect(channelSftp); safeDisconnect(channelExec1); safeDisconnect(channelExec2); } }
public void setMtime(String path, int mtime) throws SftpException { try { ((MyPipedInputStream) io_in).updateReadSide(); path = remoteAbsolutePath(path); List<String> v = glob_remote(path); int vsize = v.size(); for (String aV : v) { path = aV; SftpATTRS attr = _stat(path); attr.setFLAGS(0); attr.setACMODTIME(attr.getATime(), mtime); _setStat(path, attr); } } catch (Exception e) { if (e instanceof SftpException) { throw (SftpException) e; } throw new SftpException(SSH_FX_FAILURE, "", e); } }
/** * sets the modification time of one or several remote files. * @param path a glob pattern of the files to be reowned, relative to the * <a href="#current-directory">current remote directory</a>. * @param mtime the new modification time, in seconds from * the unix epoch. */ public void setMtime(String path, int mtime) throws SftpException{ try{ ((MyPipedInputStream)io_in).updateReadSide(); path=remoteAbsolutePath(path); Vector v=glob_remote(path); int vsize=v.size(); for(int j=0; j<vsize; j++){ path=(String)(v.elementAt(j)); SftpATTRS attr=_stat(path); attr.setFLAGS(0); attr.setACMODTIME(attr.getATime(), mtime); _setStat(path, attr); } } catch(Exception e){ if(e instanceof SftpException) throw (SftpException)e; if(e instanceof Throwable) throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e); throw new SftpException(SSH_FX_FAILURE, ""); } }
public SftpFile stat(String path) throws SshException { try { SftpATTRS attrs = channel.stat(path); return new SftpFile(convertType(attrs), path, attrs.getSize(), attrs.getMTime() * 1000, 0, attrs.getATime() * 1000, attrs.getGId(), attrs.getUId(), attrs.getPermissions()); } catch (SftpException e) { throw new net.sf.sshapi.sftp.SftpException(e.id, e.getLocalizedMessage(), 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(); } }
clientListEntry.setFullPath(currentDir +System.getProperty("file.separator")+ fileName); clientListEntry.setClientId(null); clientListEntry.setDtLastAccessed(new Date(((long) attrs.getATime()) * 1000)); clientListEntry.setDtLastModified(new Date(((long) attrs.getMTime()) * 1000)); clientListEntry.setSize(attrs.getSize()); clientListEntry.setAtime(attrs.getATime()); clientListEntry.setMtime(attrs.getMTime()); clientListEntry.setAtimeString(attrs.getAtimeString());