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


Java LsEntry類代碼示例

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


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

示例1: getRemoteFileList

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static Vector<LsEntry> getRemoteFileList(String user, String password, String addr, int port, String cwd) throws JSchException, 
	SftpException, Exception {
	
	Session session = getSession(user, password, addr, port);	
	Vector<LsEntry> lsVec=null;
	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp sftpChannel = (ChannelSftp) channel;
	try {
		lsVec=(Vector<LsEntry>)sftpChannel.ls(cwd); //sftpChannel.lpwd()
	} catch (Exception e) {
		e.printStackTrace();
		throw e;
	} finally {
		sftpChannel.exit();
		channel.disconnect();
		session.disconnect();			
	}		
	return lsVec;		
}
 
開發者ID:billchen198318,項目名稱:bamboobsc,代碼行數:22,代碼來源:SFtpClientUtils.java

示例2: listFiles

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
/**
 * Lists directory files on remote server.
 * @throws URISyntaxException 
 * @throws JSchException 
 * @throws SftpException 
 */
private void listFiles() throws URISyntaxException, JSchException, SftpException {
	
	JSch jsch = new JSch();
	JSch.setLogger(new JschLogger());
	setupSftpIdentity(jsch);

	URI uri = new URI(sftpUrl);
	Session session = jsch.getSession(sshLogin, uri.getHost(), 22);
	session.setConfig("StrictHostKeyChecking", "no");
	session.connect();
	System.out.println("Connected to SFTP server");

	Channel channel = session.openChannel("sftp");
	channel.connect();
	ChannelSftp sftpChannel = (ChannelSftp) channel;
	Vector<LsEntry> directoryEntries = sftpChannel.ls(uri.getPath());
	for (LsEntry file : directoryEntries) {
		System.out.println(String.format("File - %s", file.getFilename()));
	}
	sftpChannel.exit();
	session.disconnect();
}
 
開發者ID:szaqal,項目名稱:KitchenSink,代碼行數:29,代碼來源:App.java

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

示例4: ls

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public List<String> ls(String path)
    throws FileBasedHelperException {
  try {
    List<String> list = new ArrayList<String>();
    ChannelSftp channel = getSftpChannel();
    Vector<LsEntry> vector = channel.ls(path);
    for (LsEntry entry : vector) {
      list.add(entry.getFilename());
    }
    channel.disconnect();
    return list;
  } catch (SftpException e) {
    throw new FileBasedHelperException("Cannot execute ls command on sftp connection", e);
  }
}
 
開發者ID:Hanmourang,項目名稱:Gobblin,代碼行數:18,代碼來源:SftpFsHelper.java

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

示例6: ls

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
public static List<String> ls(String hostname, int port, String username, File keyFile, final String passphrase,
		String path) throws JSchException, IOException, SftpException {
	Session session = createSession(hostname, port, username, keyFile, passphrase);
	session.connect();
	ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
	channel.connect();
	@SuppressWarnings("unchecked")
	Vector<LsEntry> vector = (Vector<LsEntry>) channel.ls(path);
	channel.disconnect();
	session.disconnect();
	List<String> files = new ArrayList<String>();
	for (LsEntry lse : vector) {
		files.add(lse.getFilename());
	}
	return files;
}
 
開發者ID:ujmp,項目名稱:universal-java-matrix-package,代碼行數:17,代碼來源:JSchUtil.java

示例7: getFileInfo

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
@Override
public EncFSFileInfo getFileInfo(String srcPath) throws IOException {
	if ("/".equals(getAbsolutePath(srcPath))) {
		//return the root file info
		return new EncFSFileInfo("/","/",true,0,0,true,true,true);
	}
	
	Vector<LsEntry> ls = null;
	try {
		String parentPath = getParentPath(getAbsolutePath(srcPath));
		ls = getSession().ls(parentPath);
	} catch (SftpException e){
		throw new RuntimeException(e);
	}
	for (LsEntry lsEntry: ls){
		if (lsEntry.getFilename().equals(".") || lsEntry.getFilename().equals("..")) {
			continue;
		}
		
		String searchedFullPath = getAbsolutePath(srcPath);
		if (searchedFullPath.endsWith("/")) searchedFullPath=searchedFullPath.substring(0,searchedFullPath.length()-1);
		if (searchedFullPath.endsWith("/"+lsEntry.getFilename())) return LsEntry2EncFSFileInfo(getParentPath(getAbsolutePath(srcPath)),lsEntry);
	}
	return null;
	
}
 
開發者ID:starn,項目名稱:encdroidMC,代碼行數:27,代碼來源:FileProvider6.java

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

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

示例10: lsEntry

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
public Vector<LsEntry> lsEntry(String path) {
    	Vector<LsEntry> vct = new Vector<LsEntry>();
    	try {
//        	ChannelSftp.LsEntry lsEntry = (LsEntry) v.get(i);
    		Vector v = sftp.ls(path);
    		for (Object obj : v) {
				LsEntry entry = (LsEntry) obj;
				if(!".".equals(entry.getFilename()) && !"..".equals(entry.getFilename())){
					vct.add(entry);
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return new Vector<LsEntry>();
		}
    	return vct;
    }
 
開發者ID:wufeisoft,項目名稱:ryf_mms2,代碼行數:18,代碼來源:SftpUtil.java

示例11: ftpInboundFlow

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
@Bean
public IntegrationFlow ftpInboundFlow(SftpSinkProperties properties, SessionFactory<LsEntry> ftpSessionFactory) {
	SftpMessageHandlerSpec handlerSpec =
		Sftp.outboundAdapter(new SftpRemoteFileTemplate(ftpSessionFactory), properties.getMode())
			.remoteDirectory(properties.getRemoteDir())
			.remoteFileSeparator(properties.getRemoteFileSeparator())
			.autoCreateDirectory(properties.isAutoCreateDir())
			.temporaryFileSuffix(properties.getTmpFileSuffix());
	if (properties.getFilenameExpression() != null) {
		handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString());
	}
	return IntegrationFlows.from(Sink.INPUT)
		.handle(handlerSpec,
			new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>>>() {
				@Override
				public void accept(GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>> e) {
					e.autoStartup(false);
				}
			})
		.get();
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:22,代碼來源:SftpSinkConfiguration.java

示例12: traverse

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
/**
 * Delete directory and its content recursively.
 * 
 * @param channel
 *            open channel to SFTP server
 * @param path
 *            path of the directory
 * @throws SftpException
 *             when something went wrong
 */
@SuppressWarnings("unchecked")
private void traverse(ChannelSftp channel, String path)
        throws SftpException {
    SftpATTRS attrs = channel.stat(path);
    if (attrs.isDir()) {
        Vector<LsEntry> files = channel.ls(path);
        if (files != null && files.size() > 0) {
            Iterator<LsEntry> it = files.iterator();
            while (it.hasNext()) {
                LsEntry entry = it.next();
                if ((!entry.getFilename().equals(".")) && (!entry.getFilename().equals(".."))) {
                    traverse(channel, path + "/" + entry.getFilename());
                }
            }
        }
        channel.rmdir(path);
    } else {
        channel.rm(path);
    }
}
 
開發者ID:psnc-dl,項目名稱:darceo,代碼行數:31,代碼來源:SftpDataStorageClient.java

示例13: listDirectory

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public Collection<File> listDirectory(String path)
        throws IOException {
    try {
        Vector<LsEntry> files = channel.ls(path);
        List<File> result = new ArrayList<File>();
        if (files != null && files.size() > 0) {
            Iterator<LsEntry> it = files.iterator();
            while (it.hasNext()) {
                LsEntry entry = it.next();
                result.add(new File(path + "/" + entry.getFilename()));
            }
        }
        return result;
    } catch (SftpException e) {
        if (e.id == 2) {
            return Collections.emptyList();
        }
        logger.error("listing the directory failed.", e);
        throw new IOException(e);
    }
}
 
開發者ID:psnc-dl,項目名稱:darceo,代碼行數:24,代碼來源:SftpDataStorageClient.java

示例14: recursiveDelete

import com.jcraft.jsch.ChannelSftp.LsEntry; //導入依賴的package包/類
private static void recursiveDelete(ChannelSftp sftp, String path)
		throws SftpException, JSchException {
	Vector<?> entries = sftp.ls(path);
	for (Object object : entries) {
		LsEntry entry = (LsEntry) object;
		if (entry.getFilename().equals(".")
				|| entry.getFilename().equals("..")) {
			continue;
		}
		if (entry.getAttrs().isDir()) {
			recursiveDelete(sftp, path + entry.getFilename() + "/");
		} else {
			sftp.rm(path + entry.getFilename());
		}
	}
	sftp.rmdir(path);
}
 
開發者ID:apache,項目名稱:incubator-taverna-common-activities,代碼行數:18,代碼來源:SshToolInvocation.java

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


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