当前位置: 首页>>代码示例>>Java>>正文


Java LsEntry.getAttrs方法代码示例

本文整理汇总了Java中com.jcraft.jsch.ChannelSftp.LsEntry.getAttrs方法的典型用法代码示例。如果您正苦于以下问题:Java LsEntry.getAttrs方法的具体用法?Java LsEntry.getAttrs怎么用?Java LsEntry.getAttrs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcraft.jsch.ChannelSftp.LsEntry的用法示例。


在下文中一共展示了LsEntry.getAttrs方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFileStatus

import com.jcraft.jsch.ChannelSftp.LsEntry; //导入方法依赖的package包/类
/**
 * Convert the file information in LsEntry to a {@link FileStatus} object. *
 *
 * @param sftpFile
 * @param parentPath
 * @return file status
 * @throws IOException
 */
private FileStatus getFileStatus(ChannelSftp channel, LsEntry sftpFile,
    Path parentPath) throws IOException {

  SftpATTRS attr = sftpFile.getAttrs();
  long length = attr.getSize();
  boolean isDir = attr.isDir();
  boolean isLink = attr.isLink();
  if (isLink) {
    String link = parentPath.toUri().getPath() + "/" + sftpFile.getFilename();
    try {
      link = channel.realpath(link);

      Path linkParent = new Path("/", link);

      FileStatus fstat = getFileStatus(channel, linkParent);
      isDir = fstat.isDirectory();
      length = fstat.getLen();
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
  int blockReplication = 1;
  // Using default block size since there is no way in SFTP channel to know of
  // block sizes on server. The assumption could be less than ideal.
  long blockSize = DEFAULT_BLOCK_SIZE;
  long modTime = attr.getMTime() * 1000; // convert to milliseconds
  long accessTime = 0;
  FsPermission permission = getPermissions(sftpFile);
  // not be able to get the real user group name, just use the user and group
  // id
  String user = Integer.toString(attr.getUId());
  String group = Integer.toString(attr.getGId());
  Path filePath = new Path(parentPath, sftpFile.getFilename());

  return new FileStatus(length, isDir, blockReplication, blockSize, modTime,
      accessTime, permission, user, group, filePath.makeQualified(
          this.getUri(), this.getWorkingDirectory()));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:47,代码来源:SFTPFileSystem.java

示例2: LsEntry2EncFSFileInfo

import com.jcraft.jsch.ChannelSftp.LsEntry; //导入方法依赖的package包/类
private EncFSFileInfo LsEntry2EncFSFileInfo(String parentPath, LsEntry file){
	EncFSFileInfo result;
	try {
		String name = file.getFilename();

		SftpATTRS attrs = file.getAttrs();
           long mtime = attrs.getMTime();		
           boolean isDir = attrs.isDir();
           long length = attrs.getSize();
		String relativePath=this.getRelativePathFromAbsolutePath(parentPath);
           
		
		
		if (name.endsWith("/")) name=name.substring(0,name.length()-1);
		result = new EncFSFileInfo(name,relativePath,isDir,mtime,length,true,true,true);
		
	} catch (Exception e){
		throw new RuntimeException(e);
	}
	
	return result;
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:23,代码来源:FileProvider6.java

示例3: _buildFiles

import com.jcraft.jsch.ChannelSftp.LsEntry; //导入方法依赖的package包/类
private List<FileBean> _buildFiles(Vector ls,String dir) throws Exception {  
    if (ls != null && ls.size() >= 0) {  
        List<FileBean> list = new ArrayList<FileBean>();
        for (int i = 0; i < ls.size(); i++) {  
            LsEntry f = (LsEntry) ls.get(i);  
            String nm = f.getFilename();  
            
            if (nm.equals(".") || nm.equals(".."))  
                continue;  
            SftpATTRS attr = f.getAttrs();  
            FileBean fileBean=new FileBean();
            if (attr.isDir()) {  
                fileBean.setDir(true);
            } else {  
                fileBean.setDir(false);
            }  
            fileBean.setAttrs(attr);
            fileBean.setFilePath(dir);
            fileBean.setFileName(nm);
            list.add(fileBean);  
        }  
        return list;  
    }  
    return null;  
}
 
开发者ID:xnx3,项目名称:xnx3,代码行数:26,代码来源:SFTPUtil.java

示例4: listFiles

import com.jcraft.jsch.ChannelSftp.LsEntry; //导入方法依赖的package包/类
private List<FileEntry> listFiles(String path, ChannelSftp c) throws Exception {
	try {
		List<FileEntry> res = new ArrayList<FileEntry>();
		@SuppressWarnings("rawtypes")
		java.util.Vector vv = c.ls(extractSessionPath(path));
		if (vv != null) {
			for (int ii = 0; ii < vv.size(); ii++) {

				Object obj = vv.elementAt(ii);
				if (obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry) {
					LsEntry lsEntry = (com.jcraft.jsch.ChannelSftp.LsEntry) obj;

					if ((lsEntry.getFilename().equals("."))
							||(lsEntry.getFilename().equals(".."))
							)
						continue;
					
					FileEntry fileEntry = new FileEntry();
					fileEntry.displayName = lsEntry.getFilename();
					fileEntry.path = createFilePath(path, fileEntry.displayName);
					SftpATTRS attrs = lsEntry.getAttrs();
					setFromAttrs(fileEntry, attrs);
					res.add(fileEntry);
				}

			}
		}
		return res;
	} catch (Exception e) {
		tryDisconnect(c);
		throw convertException(e);
	}
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:34,代码来源:SftpStorage.java

示例5: call

import com.jcraft.jsch.ChannelSftp.LsEntry; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public StatInfo[] call() throws IOException, CancellationException, JSchException, ExecutionException, InterruptedException, SftpException {
    if (!path.startsWith("/")) { //NOI18N
        throw new FileNotFoundException("Path is not absolute: " + path); //NOI18N
    }
    List<StatInfo> result = null;
    SftpException exception = null;
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} started", getTraceName());
    }
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(PREFIX + ": " + getTraceName()); // NOI18N
    int attempt = 1;
    try {
        for (; attempt <= LS_RETRY_COUNT; attempt++) {
            ChannelSftp cftp = getChannel();
            RemoteStatistics.ActivityID lsLoadID = RemoteStatistics.startChannelActivity("lsload", path); // NOI18N
            try {
                List<LsEntry> entries = (List<LsEntry>) cftp.ls(path);
                result = new ArrayList<>(Math.max(1, entries.size() - 2));
                for (LsEntry entry : entries) {
                    String name = entry.getFilename();
                    if (!".".equals(name) && !"..".equals(name)) { //NOI18N
                        SftpATTRS attrs = entry.getAttrs();
                        //if (!(attrs.isDir() || attrs.isLink())) {
                        //    if ( (attrs.getPermissions() & S_IFMT) != S_IFREG) {
                        //        // skip not regular files
                        //        continue;
                        //    }
                        //}
                        result.add(createStatInfo(path, name, attrs, cftp));
                    }
                }
                exception = null;
                break;
            } catch (SftpException e) {
                exception = e;
                if (e.id == SftpIOException.SSH_FX_FAILURE) {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.log(Level.FINE, "{0} - exception while attempt {1}", new Object[]{getTraceName(), attempt});
                    }
                    if (MiscUtils.mightBrokeSftpChannel(e)) {
                        cftp.quit();
                    }
                } else {
                    // re-try in case of failure only
                    // otherwise consider this exception as unrecoverable
                    break;
                }
            } finally {
                RemoteStatistics.stopChannelActivity(lsLoadID);
                releaseChannel(cftp);
            }
        }
    } finally {
        Thread.currentThread().setName(threadName);
    }

    if (exception != null) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.log(Level.FINE, "{0} failed", getTraceName());
        }
        throw decorateSftpException(exception, path);
    }

    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, "{0} finished in {1} attempt(s)", new Object[]{getTraceName(), attempt});
    }

    return result == null ? new StatInfo[0] : result.toArray(new StatInfo[result.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:73,代码来源:SftpSupport.java

示例6: listFiles

import com.jcraft.jsch.ChannelSftp.LsEntry; //导入方法依赖的package包/类
public List<SshFile> listFiles(String path) {
    path = getAbsolutePath(path);

    try {
        Vector vector = getSftpChannel().ls(path);
        if (vector == null || vector.isEmpty()) {
            return Collections.EMPTY_LIST;
        }

        List<SshFile> sshFiles = new ArrayList<>(vector.size());
        for (Iterator<LsEntry> iter = vector.iterator(); iter.hasNext(); ) {
            LsEntry entry = iter.next();

            String filename = entry.getFilename();
            if (filename.equals(".") || filename.equals("..")) {
                continue;
            }

            SftpATTRS attr = entry.getAttrs();
            SshFile file = new SshFile();
            file.setName(entry.getFilename());
            String filePath = createPath(path, entry.getFilename());
            file.setPath(getAbsolutePath(filePath));
            file.setLength(attr.getSize());
            FilePermission permission = new FilePermission(attr.getPermissions());
            file.setPermission(permission);
            FileType t = FileType.parse(attr.getPermissions() & FileType.S_IFMT);
            file.setType(t);

            List<String> tokens = splitStringAndOmitEmpty(entry.getLongname(), " ");
            String owner = tokens.get(2);
            String group = tokens.get(3);

            file.setOwner(owner);
            file.setGroup(group);

            file.setLastAccessTime(new Date(((long) attr.getATime()) * 1000L));
            file.setLastModifiedTime(new Date(((long) attr.getMTime()) * 1000L));
            sshFiles.add(file);
        }
        return sshFiles;
    } catch (Exception e) {
        if (e instanceof SshException) {
            throw (SshException) e;
        }
        throw new SshException(e);
    }
}
 
开发者ID:huiyu,项目名称:ssh4j,代码行数:49,代码来源:SshClient.java


注:本文中的com.jcraft.jsch.ChannelSftp.LsEntry.getAttrs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。