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


Java ChannelSftp.LsEntry方法代碼示例

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


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

示例1: listFiles

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private List<String> listFiles(String path, List<String> list, String prefix, boolean root) {
    Vector<ChannelSftp.LsEntry> children = util.ls(path);
    if(null != children) {
        for (ChannelSftp.LsEntry entry : children) {
            if(entry.getAttrs().isDir()) {
                listFiles(path + "/" + entry.getFilename(), list,
                        root ? entry.getFilename() : (prefix + "/" + entry.getFilename()), false);
            } else {
                String ret = FilterChain.filter(entry.getFilename());
                if(null != ret) {
                    list.add(root ? ret : prefix + "/" + ret);
                }
            }
        }
    }
    return list;
}
 
開發者ID:hetianyi,項目名稱:easy-sync,代碼行數:18,代碼來源:SFTPSyncClient.java

示例2: getDir

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void getDir(final ChannelSftp channel,
                    final String remoteFile,
                    final File localFile) throws IOException, SftpException {
    String pwd = remoteFile;
    if (remoteFile.lastIndexOf('/') != -1) {
        if (remoteFile.length() > 1) {
            pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/'));
        }
    }
    channel.cd(pwd);
    if (!localFile.exists()) {
        localFile.mkdirs();
    }
    @SuppressWarnings("unchecked")
    final List<ChannelSftp.LsEntry> files = channel.ls(remoteFile);
    for (ChannelSftp.LsEntry le : files) {
        final String name = le.getFilename();
        if (le.getAttrs().isDir()) {
            if (".".equals(name) || "..".equals(name)) {
                continue;
            }
            getDir(channel,
                   channel.pwd() + "/" + name + "/",
                   new File(localFile, le.getFilename()));
        } else {
            getFile(channel, le, localFile);
        }
    }
    channel.cd("..");
}
 
開發者ID:apache,項目名稱:ant,代碼行數:31,代碼來源:ScpFromMessageBySftp.java

示例3: listFiles

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
public synchronized List<ChannelSftp.LsEntry> listFiles(String path) throws GenericFileOperationFailedException {
    LOG.trace("listFiles({})", path);
    if (ObjectHelper.isEmpty(path)) {
        // list current directory if file path is not given
        path = ".";
    }

    try {
        final List<ChannelSftp.LsEntry> list = new ArrayList<ChannelSftp.LsEntry>();

        @SuppressWarnings("rawtypes")
        Vector files = channel.ls(path);
        // can return either null or an empty list depending on FTP servers
        if (files != null) {
            for (Object file : files) {
                list.add((ChannelSftp.LsEntry) file);
            }
        }
        return list;
    } catch (SftpException e) {
        throw new GenericFileOperationFailedException("Cannot list directory: " + path, e);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:SftpOperations.java

示例4: pollDirectory

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
protected boolean pollDirectory(String fileName, List<GenericFile<ChannelSftp.LsEntry>> fileList, int depth) {
    String currentDir = null;
    if (isStepwise()) {
        // must remember current dir so we stay in that directory after the poll
        currentDir = operations.getCurrentDirectory();
    }

    // strip trailing slash
    fileName = FileUtil.stripTrailingSeparator(fileName);

    boolean answer = doPollDirectory(fileName, null, fileList, depth);
    if (currentDir != null) {
        operations.changeCurrentDirectory(currentDir);
    }

    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:SftpConsumer.java

示例5: buildFileEndpoint

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
protected GenericFileEndpoint<ChannelSftp.LsEntry> buildFileEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // get the base uri part before the options as they can be non URI valid such as the expression using $ chars
    // and the URI constructor will regard $ as an illegal character and we dont want to enforce end users to
    // to escape the $ for the expression (file language)
    String baseUri = uri;
    if (uri.indexOf("?") != -1) {
        baseUri = uri.substring(0, uri.indexOf("?"));
    }

    // lets make sure we create a new configuration as each endpoint can
    // customize its own version
    SftpConfiguration config = new SftpConfiguration(new URI(baseUri));

    FtpUtils.ensureRelativeFtpDirectory(this, config);

    return new SftpEndpoint(uri, this, config);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:SftpComponent.java

示例6: getFile

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void getFile(final ChannelSftp channel,
                     final ChannelSftp.LsEntry le,
                     File localFile) throws IOException, SftpException {
    final String remoteFile = le.getFilename();
    if (!localFile.exists()) {
        final String path = localFile.getAbsolutePath();
        final int i = path.lastIndexOf(File.pathSeparator);
        if (i != -1) {
            if (path.length() > File.pathSeparator.length()) {
                new File(path.substring(0, i)).mkdirs();
            }
        }
    }

    if (localFile.isDirectory()) {
        localFile = new File(localFile, remoteFile);
    }

    final long startTime = System.currentTimeMillis();
    final long totalLength = le.getAttrs().getSize();

    SftpProgressMonitor monitor = null;
    final boolean trackProgress = getVerbose() && totalLength > HUNDRED_KILOBYTES;
    if (trackProgress) {
        monitor = getProgressMonitor();
    }
    try {
        log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize());
        channel.get(remoteFile, localFile.getAbsolutePath(), monitor);
    } finally {
        final long endTime = System.currentTimeMillis();
        logStats(startTime, endTime, (int) totalLength);
    }
    if (getPreserveLastModified()) {
        FileUtils.getFileUtils().setFileLastModified(localFile,
                                                     ((long) le.getAttrs()
                                                      .getMTime())
                                                     * 1000);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:41,代碼來源:ScpFromMessageBySftp.java

示例7: rm

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void rm(String path, ChannelSftp.LsEntry entry) throws SftpException {

        if (!entry.getAttrs().isDir()) {
            channelsftp.rm(path + "/" + entry.getFilename());
        } else {
            //cd into the dir
            channelsftp.cd(path + "/" + entry.getFilename());

            Vector vec = channelsftp.ls(channelsftp.pwd());

            for (Object o : vec) {
                if (o instanceof ChannelSftp.LsEntry) {
                    ChannelSftp.LsEntry local_entry = (ChannelSftp.LsEntry) o;

                    if (!local_entry.getFilename().equals(".") && !local_entry.getFilename().equals("..")) {
                        rm(channelsftp.pwd(), local_entry);
                    }
                }
            }
            channelsftp.rmdir(path + "/" + entry.getFilename());
            channelsftp.cd(path);
        }
    }
 
開發者ID:xiaoerge,項目名稱:File-UI,代碼行數:24,代碼來源:GUI.java

示例8: doSelectAdd

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void doSelectAdd(ChannelSftp.LsEntry entry) {
    try {
        if (entry.getFilename().equals(".")) {
            //ignore current directory
        } else if (entry.getFilename().equals("..")) {
            main_view.addEntry(entry);
        } else if (entry.getFilename().startsWith(".")) {
            //ignore hidden files
        } //optimize this block
        else {
            main_view.addEntry(entry);
        }
    } catch (Exception ex) {
        menu_view.status_lb.setText(ex.getMessage());
    }
}
 
開發者ID:xiaoerge,項目名稱:File-UI,代碼行數:17,代碼來源:GUI.java

示例9: getNodes

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
public synchronized List<Node> getNodes(String path) {
    List<Node> nodes = new ArrayList<>();

    if ((session == null) || !session.isConnected()) {
        return nodes;
    }

    for (ChannelSftp.LsEntry entry : getFiles(path)) {
        Node node = new Node();
        nodes.add(node);
        node.setName(entry.getFilename());
        if (path.endsWith("/")) {
            node.setPath(path + entry.getFilename());
        } else {
            node.setPath(path + "/" + entry.getFilename());
        }

        if (entry.getAttrs().isLink()) {
            processSymLink(node);
        } else {
            node.setFile(!entry.getAttrs().isDir());
        }
    }
    Collections.sort(nodes);
    return nodes;
}
 
開發者ID:malafeev,項目名稱:JFTClient,代碼行數:27,代碼來源:Connection.java

示例10: locateEntry

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private ChannelSftp.LsEntry locateEntry(Vector<ChannelSftp.LsEntry> list, String name) {
	for (ChannelSftp.LsEntry file : list) {
		if (file.getFilename().equals(name)) {
			return file;
		}
	}
	return null;
	
}
 
開發者ID:gchq,項目名稱:stroom-agent,代碼行數:10,代碼來源:SFTPTransfer.java

示例11: existsFile

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
public synchronized boolean existsFile(String name) throws GenericFileOperationFailedException {
    LOG.trace("existsFile({})", name);
    if (endpoint.isFastExistsCheck()) {
        return fastExistsFile(name);
    }
    // check whether a file already exists
    String directory = FileUtil.onlyPath(name);
    if (directory == null) {
        // assume current dir if no path could be extracted
        directory = ".";
    }
    String onlyName = FileUtil.stripPath(name);

    try {
        @SuppressWarnings("rawtypes")
        Vector files = channel.ls(directory);
        // can return either null or an empty list depending on FTP servers
        if (files == null) {
            return false;
        }
        for (Object file : files) {
            ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) file;
            String existing = entry.getFilename();
            LOG.trace("Existing file: {}, target file: {}", existing, name);
            existing = FileUtil.stripPath(existing);
            if (existing != null && existing.equals(onlyName)) {
                return true;
            }
        }
        return false;
    } catch (SftpException e) {
        // or an exception can be thrown with id 2 which means file does not exists
        if (ChannelSftp.SSH_FX_NO_SUCH_FILE == e.id) {
            return false;
        }
        // otherwise its a more serious error so rethrow
        throw new GenericFileOperationFailedException(e.getMessage(), e);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:40,代碼來源:SftpOperations.java

示例12: pollSubDirectory

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
protected boolean pollSubDirectory(String absolutePath, String dirName, List<GenericFile<ChannelSftp.LsEntry>> fileList, int depth) {
    boolean answer = doSafePollSubDirectory(absolutePath, dirName, fileList, depth);
    // change back to parent directory when finished polling sub directory
    if (isStepwise()) {
        operations.changeToParentDirectory();
    }
    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:9,代碼來源:SftpConsumer.java

示例13: asRemoteFile

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private RemoteFile<ChannelSftp.LsEntry> asRemoteFile(String absolutePath, ChannelSftp.LsEntry file, String charset) {
    RemoteFile<ChannelSftp.LsEntry> answer = new RemoteFile<ChannelSftp.LsEntry>();

    answer.setCharset(charset);
    answer.setEndpointPath(endpointPath);
    answer.setFile(file);
    answer.setFileNameOnly(file.getFilename());
    answer.setFileLength(file.getAttrs().getSize());
    answer.setLastModified(file.getAttrs().getMTime() * 1000L);
    answer.setHostname(((RemoteFileConfiguration) endpoint.getConfiguration()).getHost());
    answer.setDirectory(file.getAttrs().isDir());

    // absolute or relative path
    boolean absolute = FileUtil.hasLeadingSeparator(absolutePath);
    answer.setAbsolute(absolute);

    // create a pseudo absolute name
    String dir = FileUtil.stripTrailingSeparator(absolutePath);
    String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + file.getFilename());
    // if absolute start with a leading separator otherwise let it be relative
    if (absolute) {
        absoluteFileName = "/" + absoluteFileName;
    }
    answer.setAbsoluteFilePath(absoluteFileName);

    // the relative filename, skip the leading endpoint configured path
    String relativePath = ObjectHelper.after(absoluteFileName, endpointPath);
    // skip trailing /
    relativePath = FileUtil.stripLeadingSeparator(relativePath);
    answer.setRelativeFilePath(relativePath);

    // the file name should be the relative path
    answer.setFileName(answer.getRelativeFilePath());

    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:37,代碼來源:SftpConsumer.java

示例14: updateFileHeaders

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
protected void updateFileHeaders(GenericFile<ChannelSftp.LsEntry> file, Message message) {
    long length = file.getFile().getAttrs().getSize();
    long modified = file.getFile().getAttrs().getMTime() * 1000L;
    file.setFileLength(length);
    file.setLastModified(modified);
    if (length >= 0) {
        message.setHeader(Exchange.FILE_LENGTH, length);
    }
    if (modified >= 0) {
        message.setHeader(Exchange.FILE_LAST_MODIFIED, modified);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:14,代碼來源:SftpConsumer.java

示例15: lsEntryToFilename

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
/**
 * Returns a filename for an lsEntry.
 */
@CheckForNull
public static String lsEntryToFilename( final ChannelSftp.LsEntry lsEntry ) {
    if ( lsEntry != null ) {
        final String filename = lsEntry.getFilename();
        if ( !Strings.isNullOrEmpty( filename ) ) {
            return filename;
        }
    }
    return null;
}
 
開發者ID:freiheit-com,項目名稱:fuava_simplebatch,代碼行數:14,代碼來源:SftpOldFilesMovingLatestMultiFileFetcher.java


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