@Override public long getFileMTime(String filePath) throws FileBasedHelperException { ChannelSftp channelSftp = null; try { channelSftp = getSftpChannel(); int modificationTime = channelSftp.lstat(filePath).getMTime(); return modificationTime; } catch (SftpException e) { throw new FileBasedHelperException( String.format("Failed to get modified timestamp for file at path %s due to error %s", filePath, e.getMessage()), e); } finally { if (channelSftp != null) { channelSftp.disconnect(); } } }
long modTime = attr.getMTime() * 1000L; // convert to milliseconds 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); } }
private FileInfo newFileInfo(final LsEntry entry, String path) { if (entry == null) { return null; } final File newFullPath = new File(path, entry.getFilename()); final String newFullForwardPath = newFullPath.getPath().replace("\\", "/"); String perms = entry.getAttrs().getPermissionsString(); if (perms.length() > 9) { perms = perms.substring(perms.length() - 9); } FileInfo.Builder builder = new FileInfo.Builder() .filename(entry.getFilename()) .fullPathFileName(newFullForwardPath) .directory(entry.getAttrs().isDir()) .size(entry.getAttrs().getSize()) .lastModifiedTime(entry.getAttrs().getMTime() * 1000L) .permissions(perms) .owner(Integer.toString(entry.getAttrs().getUId())) .group(Integer.toString(entry.getAttrs().getGId())); return builder.build(); }
/** * @see com.jcraft.jsch.SftpATTRS#getMTime() */ @Override public long getModified() { return ((long) this.attrs.getMTime()) * 1000; }
@Override protected long getModified(LsEntry file) { return (long) file.getAttrs().getMTime() * 1000; }
@Override protected long modified(LsEntry file) { return ((long) file.getAttrs().getMTime()) * 1000; }
@Override protected long getModified(LsEntry file) { return ((long) file.getAttrs().getMTime()) * 1000; }
oldestFile = lsEntry.getFilename(); attrs = lsEntry.getAttrs(); currentOldestTime = attrs.getMTime(); for (Object sftpFile : list) { lsEntry = (ChannelSftp.LsEntry) sftpFile; nextName = lsEntry.getFilename(); attrs = lsEntry.getAttrs(); nextTime = attrs.getMTime(); if (nextTime < currentOldestTime) { oldestFile = nextName;
private void init() { String[] files = new File("remote-test-dir").list(); for (String fileName : files) { LsEntry lsEntry = mock(LsEntry.class); SftpATTRS attributes = mock(SftpATTRS.class); when(lsEntry.getAttrs()).thenReturn(attributes); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); when(lsEntry.getAttrs().getMTime()).thenReturn(new Long(calendar.getTimeInMillis() / 1000).intValue()); when(lsEntry.getFilename()).thenReturn(fileName); when(lsEntry.getLongname()).thenReturn(fileName); sftpEntries.add(lsEntry); } }
@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()); }
/** * @see com.jcraft.jsch.SftpATTRS#getMTime() */ @Override public long getModified() { return ((long) this.attrs.getMTime()) * 1000; }
@Override public long getLastModified() { return entry.getAttrs().getMTime() * 1000L; } }
@Override /** * @return boolean * @param Object to check */ public long getModifiedTime(ChannelSftp.LsEntry file) { return file.getAttrs().getMTime() * 1000L; }
@Override protected long doGetLastModifiedTime() throws Exception { if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) == 0) { throw new FileSystemException("vfs.provider.sftp/unknown-modtime.error"); } return attrs.getMTime() * MOD_TIME_FACTOR; }
@Override protected long doGetLastModifiedTime() throws Exception { if (attrs == null || (attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) == 0) { throw new FileSystemException("vfs.provider.sftp/unknown-modtime.error"); } return attrs.getMTime() * MOD_TIME_FACTOR; }
private LsEntry createSingleEntry(String fileName, long size, int mTime, boolean directory) { SftpATTRS attributes = mock(SftpATTRS.class); when(attributes.getSize()).thenReturn(size); when(attributes.getMTime()).thenReturn(mTime); LsEntry entry = mock(LsEntry.class); when(entry.getAttrs()).thenReturn(attributes); when(entry.getFilename()).thenReturn(fileName); when(entry.getAttrs().isDir()).thenReturn(directory); return entry; } }
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); } }
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); } }
private FileEntry getFileEntry( LsEntry lsEntry, String parentPath ) { FileEntry fileEntry = new FileEntry(lsEntry.getFilename(), IoUtils.normalizeUnixDir(parentPath) + lsEntry.getFilename(), lsEntry.getAttrs().isDir()); fileEntry.setSize(lsEntry.getAttrs().getSize()); fileEntry.setParentPath(parentPath); fileEntry.setLastModificationTime(lsEntry.getAttrs().getMTime()); return fileEntry; }