當前位置: 首頁>>代碼示例>>Java>>正文


Java LsEntry.getFilename方法代碼示例

本文整理匯總了Java中com.jcraft.jsch.ChannelSftp.LsEntry.getFilename方法的典型用法代碼示例。如果您正苦於以下問題:Java LsEntry.getFilename方法的具體用法?Java LsEntry.getFilename怎麽用?Java LsEntry.getFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.jcraft.jsch.ChannelSftp.LsEntry的用法示例。


在下文中一共展示了LsEntry.getFilename方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: listEntries

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private Vector<LsEntry> listEntries(final ChannelSftp channelSftp, final String path) throws SftpException {
    final Vector<LsEntry> vector = new Vector<LsEntry>();

    LsEntrySelector selector = new LsEntrySelector() {
        public int select(LsEntry entry)  {
            final String filename = entry.getFilename();
            if (filename.equals(".") || filename.equals("..")) {
                return CONTINUE;
            }
            if (entry.getAttrs().isLink()) {
                vector.addElement(entry);
            }
            else if (entry.getAttrs().isDir()) {
                if (keepDirectory(filename)) {
                    vector.addElement(entry);
                }
            }
            else {
                 if (keepFile(filename)) {
                    vector.addElement(entry);
                }
            }
            return CONTINUE;
        }
    };

    channelSftp.ls(path, selector);
    return vector;
}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:30,代碼來源:SFtpListingEngine.java

示例2: 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

示例3: 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

示例4: _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

示例5: acceptListedFile

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
/**
 * Filters the "." and ".." directories 
 */
private boolean acceptListedFile(LsEntry file) {
	if (file == null || file.getFilename() == null) {
		return false;
	}
	
	String name = file.getFilename().trim().toLowerCase();
	return (
			! (
					name.endsWith("/..") 
					|| name.endsWith("\\..")
					|| name.endsWith("/.")
					|| name.endsWith("\\.")
					|| name.equals("..")
					|| name.equals(".")
			)
	);
}
 
開發者ID:chfoo,項目名稱:areca-backup-release-mirror,代碼行數:21,代碼來源:SFTPProxy.java

示例6: 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

示例7: getFileEntry

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
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;
    }
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:11,代碼來源:JschSftpClient.java

示例8: ls

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
/**
 * Issue an 'ls' command on remote server and exclussively print the values or return them in a String array.
 * 
 * @param folder
 *            to issue the 'ls' command on
 * @param printInfo
 * @return
 * @throws SftpException
 */
public String[] ls(String folder, boolean printInfo) throws SftpException {
	List fileList = cmd.ls(folder);
	String[] filenames = null;

	if (fileList != null) {

		//only instantiate array to hold ls results if user is not printing info
		if (!printInfo){
			filenames = new String[fileList.size()];
		}

		logger.debug("ls " + folder);
		int i = 0;
		for (Object obj : fileList) {

			if (obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry) {
				LsEntry lsEntry = (LsEntry) obj;

				//either print or store each element
				if (printInfo) {
					logger.debug(lsEntry.getFilename());
				} else {
					String fn = lsEntry.getFilename(); //filename
					if (fn != null && !fn.equals(".") && !fn.equals("..")) {
						filenames[i++] = fn;
					}
				}
			}
		}
	}

	return filenames;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:43,代碼來源:SFTPConnector.java

示例9: toFtpFile

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private JFTPFile toFtpFile(LsEntry lsEntry, String filePath) throws SftpException {

        String name = lsEntry.getFilename();
        long fileSize = lsEntry.getAttrs().getSize();
        String fullPath = String.format("%s%s%s", filePath, "/", lsEntry.getFilename());
        //   String fullPath = channel.realpath(filePath); //為何不用這個
        int mTime = lsEntry.getAttrs().getMTime();
        boolean directory = lsEntry.getAttrs().isDir();

        return new JFTPFile(name, fileSize, fullPath, (long) mTime * MILLIS, directory);
    }
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:12,代碼來源:SftpConnection.java

示例10: toFtpFile

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private FTPFile toFtpFile(LsEntry lsEntry, String filePath) throws SftpException {

        String name = lsEntry.getFilename();
        long fileSize = lsEntry.getAttrs().getSize();
        int mTime = lsEntry.getAttrs().getMTime();
        boolean directory = lsEntry.getAttrs().isDir();

        return new FTPFile(name, fileSize, filePath, (long) mTime * 1000, directory);
    }
 
開發者ID:linuxserver,項目名稱:davos,代碼行數:10,代碼來源:SFTPConnection.java

示例11: getSFTPMatchingPathes

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private static List<String> getSFTPMatchingPathes(String path, String[] pathStream, ArrayList<String> arrayList, ChannelSftp fc, DateTime lastReadout, DateTimeFormatterBuilder dtfbuilder) {
        int nextTokenPos = getPathTokens(path).length;
        if (nextTokenPos == pathStream.length - 1) {
            arrayList.add(path);
            return arrayList;
        }

        String nextToken = pathStream[nextTokenPos];
        String nextFolder = null;

        try {
            if (containsDateToken(nextToken)) {
                Vector listDirectories = fc.ls(path);
                for (Object folder : listDirectories) {
                    LsEntry currentFolder = (LsEntry) folder;

                    if (!matchDateString(currentFolder.getFilename(), nextToken)) {
                        continue;
                    }
                    DateTime folderTime = getFolderTime(path + currentFolder.getFilename() + "/", pathStream);
                    if (folderTime.isAfter(lastReadout)) {
                        nextFolder = currentFolder.getFilename();
                        getSFTPMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder);
                    }
//                    }
                }
            } else {
                nextFolder = nextToken;
                getSFTPMatchingPathes(path + nextFolder + "/", pathStream, arrayList, fc, lastReadout, dtfbuilder);
            }
        } catch (SftpException ex) {
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable files on the device");
        }
        return arrayList;
    }
 
開發者ID:OpenJEVis,項目名稱:JECommons,代碼行數:36,代碼來源:DataSourceHelper.java

示例12: toFtpFile

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
private FtpFile toFtpFile(LsEntry lsEntry, String filePath) throws SftpException {

        String name = lsEntry.getFilename();
        long fileSize = lsEntry.getAttrs().getSize();
        String fullPath = String.format("%s%s%s", filePath, FILE_SEPARATOR, lsEntry.getFilename());
        int mTime = lsEntry.getAttrs().getMTime();
        boolean directory = lsEntry.getAttrs().isDir();

        return new FtpFile(name, fileSize, fullPath, (long) mTime * MILLIS, directory);
    }
 
開發者ID:JAGFin1,項目名稱:JFTP,代碼行數:11,代碼來源:SftpConnection.java

示例13: 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

示例14: 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

示例15: getSFTPMatchedFileNames

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入方法依賴的package包/類
public static List<String> getSFTPMatchedFileNames(ChannelSftp _channel, DateTime lastReadout, String filePath) {
        filePath = filePath.replace("\\", "/");
        String[] pathStream = getPathTokens(filePath);

        String startPath = "";
        if (filePath.startsWith("/")) {
            startPath = "/";
        }

        List<String> folderPathes = getSFTPMatchingPathes(startPath, pathStream, new ArrayList<String>(), _channel, lastReadout, new DateTimeFormatterBuilder());
//        System.out.println("foldersize,"+folderPathes.size());
        List<String> fileNames = new ArrayList<String>();
        if (folderPathes.isEmpty()) {
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable folder on the device");
            return fileNames;
        }

        if (folderPathes.isEmpty()) {
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable folder on the device");
            return fileNames;
        }

        String fileNameScheme = pathStream[pathStream.length - 1];
        String currentfolder = null;
        try {
            for (String folder : folderPathes) {
                //                fc.changeWorkingDirectory(folder);
                //                System.out.println("currentFolder,"+folder);
                currentfolder = folder;
                //                for (FTPFile file : fc.listFiles(folder)) {
                //                    System.out.println(file.getName());
                //                }
//                Vector ls = _channel.ls(folder);
                for (Object fileName : _channel.ls(folder)) {
                    LsEntry currentFile = (LsEntry) fileName;
                    String currentFileName = currentFile.getFilename();
                    currentFileName = removeFoler(currentFileName, folder);
                    boolean match = false;
                    System.out.println(currentFileName);
                    if (DataSourceHelper.containsTokens(fileNameScheme)) {
                        boolean matchDate = matchDateString(currentFileName, fileNameScheme);
                        DateTime folderTime = getFileTime(folder + currentFileName, pathStream);
                        boolean isLater = folderTime.isAfter(lastReadout);
                        if (matchDate && isLater) {
                            match = true;
                        }
                    } else {
                        Pattern p = Pattern.compile(fileNameScheme);
                        Matcher m = p.matcher(currentFileName);
                        match = m.matches();
                    }
                    if (match) {
                        fileNames.add(folder + currentFileName);
                    }
                }
            }
        } catch (Exception ex) {
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Error while searching a matching file");
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Folder: " + currentfolder);
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "FileName: " + fileNameScheme);
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, ex.getMessage());
        }
        if (folderPathes.isEmpty()) {
            org.apache.log4j.Logger.getLogger(DataSourceHelper.class).log(org.apache.log4j.Level.ERROR, "Cant find suitable files on the device");
        }
//        System.out.println("filenamesize"+fileNames.size());
        return fileNames;
    }
 
開發者ID:OpenJEVis,項目名稱:JECommons,代碼行數:69,代碼來源:DataSourceHelper.java


注:本文中的com.jcraft.jsch.ChannelSftp.LsEntry.getFilename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。