Java Code Examples for com.jcraft.jsch.SftpATTRS#getMTime()

The following examples show how to use com.jcraft.jsch.SftpATTRS#getMTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SftpSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private StatInfo createStatInfo(String dirName, String baseName, SftpATTRS attrs, ChannelSftp cftp) throws SftpException {
    String linkTarget = null;
    if (attrs.isLink()) {
        String path = dirName + '/' + baseName;
        RemoteStatistics.ActivityID activityID = RemoteStatistics.startChannelActivity("readlink", path); // NOI18N
        try {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "performing readlink {0}", path);
            }
            linkTarget = cftp.readlink(path);
        } finally {
            RemoteStatistics.stopChannelActivity(activityID);
        }
    }
    Date lastModified = new Date(attrs.getMTime() * 1000L);
    StatInfo result = new FileInfoProvider.StatInfo(baseName, attrs.getUId(), attrs.getGId(), attrs.getSize(),
            attrs.isDir(), attrs.isLink(), linkTarget, attrs.getPermissions(), lastModified);
    return result;
}
 
Example 2
Source File: SFTPRepository.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
/**
 * This method is similar to getResource, except that the returned resource is fully initialized
 * (resolved in the sftp repository), and that the given string is a full remote path
 *
 * @param path
 *            the full remote path in the repository of the resource
 * @return a fully initialized resource, able to answer to all its methods without needing any
 *         further connection
 */
@SuppressWarnings("unchecked")
public Resource resolveResource(String path) {
    try {
        List<LsEntry> r = getSftpChannel(path).ls(getPath(path));
        if (r != null) {
            SftpATTRS attrs = r.get(0).getAttrs();
            return new BasicResource(path, true, attrs.getSize(),
                        attrs.getMTime() * MILLIS_PER_SECOND, false);
        }
    } catch (Exception e) {
        Message.debug("Error while resolving resource " + path, e);
        // silent fail, return nonexistent resource
    }

    return new BasicResource(path, false, 0, 0, false);
}
 
Example 3
Source File: SftpResourceAccessor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExternalResourceMetaData toMetaData(URI uri, SftpATTRS attributes) {
    long lastModified = -1;
    long contentLength = -1;

    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
        lastModified = attributes.getMTime() * 1000;
    }
    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0) {
        contentLength = attributes.getSize();
    }

    return new DefaultExternalResourceMetaData(uri, lastModified, contentLength, null, null);
}
 
Example 4
Source File: SftpResourceAccessor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ExternalResourceMetaData toMetaData(URI uri, SftpATTRS attributes) {
    long lastModified = -1;
    long contentLength = -1;

    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_ACMODTIME) != 0) {
        lastModified = attributes.getMTime() * 1000;
    }
    if ((attributes.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_SIZE) != 0) {
        contentLength = attributes.getSize();
    }

    return new DefaultExternalResourceMetaData(uri, lastModified, contentLength, null, null);
}
 
Example 5
Source File: SftpLightWeightFileSystem.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@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);
  }

}