コード例 #1
0
ファイル: ScpFromMessage.java プロジェクト: KOST-CECO/SIP-Val
 private void setLastModified(File localFile) throws JSchException {
   SftpATTRS fileAttributes = null;
   String remotePath = null;
   ChannelSftp channel = openSftpChannel();
   channel.connect();
   try {
     fileAttributes = channel.lstat(remoteDir(remoteFile) + localFile.getName());
   } catch (SftpException e) {
     throw new JSchException("failed to stat remote file", e);
   }
   FileUtils.getFileUtils()
       .setFileLastModified(localFile, ((long) fileAttributes.getMTime()) * 1000);
 }
コード例 #2
0
  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);
  }
コード例 #3
0
ファイル: SFTPRepository.java プロジェクト: pombredanne/ivy
  /**
   * 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
   */
  public Resource resolveResource(String path) {
    try {
      ChannelSftp c = getSftpChannel(path);

      Collection r = c.ls(getPath(path));

      if (r != null) {
        for (Iterator iter = r.iterator(); iter.hasNext(); ) {
          Object obj = iter.next();
          if (obj instanceof LsEntry) {
            LsEntry entry = (LsEntry) obj;
            SftpATTRS attrs = entry.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 unexisting resource
    }

    return new BasicResource(path, false, 0, 0, false);
  }