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


Java ChannelSftp.stat方法代碼示例

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


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

示例1: sendDirectoryToRemote

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void sendDirectoryToRemote(final ChannelSftp channel,
                                   final Directory directory)
    throws IOException, SftpException {
    final String dir = directory.getDirectory().getName();
    try {
        channel.stat(dir);
    } catch (final SftpException e) {
        // dir does not exist.
        if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
            channel.mkdir(dir);
            channel.chmod(getDirMode(), dir);
        }
    }
    channel.cd(dir);
    sendDirectory(channel, directory);
    channel.cd("..");
}
 
開發者ID:apache,項目名稱:ant,代碼行數:18,代碼來源:ScpToMessageBySftp.java

示例2: createRemotePath

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void createRemotePath(@NotNull final ChannelSftp channel,
                              @NotNull final String destination) throws SftpException {
  final int endIndex = destination.lastIndexOf('/');
  if (endIndex > 0) {
    createRemotePath(channel, destination.substring(0, endIndex));
  }
  try {
    channel.stat(destination);
  } catch (SftpException e) {
    // dir does not exist.
    if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
      channel.mkdir(destination);
    }
  }

}
 
開發者ID:JetBrains,項目名稱:teamcity-deployer-plugin,代碼行數:17,代碼來源:SftpBuildProcessAdapter.java

示例3: getFileEntry

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
public FileEntry getFileEntry(String filename) throws Exception {

	ChannelSftp c = init(filename);
	try {
		FileEntry fileEntry = new FileEntry();
		String sessionPath = extractSessionPath(filename);
		SftpATTRS attr = c.stat(sessionPath);
		setFromAttrs(fileEntry, attr);
		fileEntry.path = filename;
		fileEntry.displayName = getFilename(sessionPath);
		tryDisconnect(c);
		return fileEntry;
	} catch (Exception e) {
		logDebug("Exception in getFileEntry! " + e);
		tryDisconnect(c);
		throw convertException(e);
	}
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:20,代碼來源:SftpStorage.java

示例4: traverse

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的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

示例5: execute

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
protected void execute() throws SftpResult, JSchException {
    ChannelSftp ch = channel();
    try {
        SftpATTRS attrs = ch.stat(path);
        throw new SftpResult(attrs);
    } catch (SftpException e) {
        if (e.id == SSH_FX_NO_SUCH_FILE) {
            throw new SftpResult(null);
        } else {
            throw new SftpError(e, "Error checking stat of %s", path);
        }
    } finally {
        release(ch);
    }
}
 
開發者ID:osglworks,項目名稱:java-sftp,代碼行數:17,代碼來源:Stat.java

示例6: isDir

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private boolean isDir(String path) {
    ChannelSftp sftp = getSftpChannel();
    try {
        SftpATTRS attrs = sftp.stat(path);
        return attrs.isDir();
    } catch (SftpException e) {
        throw new SshException(e);
    }
}
 
開發者ID:huiyu,項目名稱:ssh4j,代碼行數:10,代碼來源:SshClient.java

示例7: getFileStatus

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
public FileStatus getFileStatus(Path path) throws IOException {
  ChannelSftp channelSftp = null;
  ChannelExec channelExec1 = null;
  ChannelExec channelExec2 = null;
  try {
    channelSftp = fsHelper.getSftpChannel();
    SftpATTRS sftpAttrs = channelSftp.stat(path.toString());
    FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions());

    channelExec1 = fsHelper.getExecChannel("id " + sftpAttrs.getUId());
    String userName = IOUtils.toString(channelExec1.getInputStream());


    channelExec2 = fsHelper.getExecChannel("id " + sftpAttrs.getGId());
    String groupName = IOUtils.toString(channelExec2.getInputStream());

    FileStatus fs =
        new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, (long) sftpAttrs.getMTime(),
            (long) sftpAttrs.getATime(), permission, StringUtils.trimToEmpty(userName),
            StringUtils.trimToEmpty(groupName), path);

    return fs;
  } catch (SftpException e) {
    throw new IOException(e);
  } finally {
    safeDisconnect(channelSftp);
    safeDisconnect(channelExec1);
    safeDisconnect(channelExec2);
  }

}
 
開發者ID:Hanmourang,項目名稱:Gobblin,代碼行數:33,代碼來源:SftpLightWeightFileSystem.java

示例8: _ensurePath

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void _ensurePath(ChannelSftp channel, FTPClient ftpClient, String path, boolean excludeLast) throws Exception {
    String buildPath = "";
    if (path.substring(0, 1).equals("/")) {
        path = path.substring(1);
        buildPath += "/";
    }

    String[] pathSegments = path.split("/");
    int size = pathSegments.length;

    if (excludeLast) {
        size -= 1;
    }

    for (int i=0; i<size; i++) {
        buildPath += pathSegments[i] + "/";

        if (channel != null) {
            try {
                channel.stat(buildPath);
            } catch (Exception e) {
                channel.mkdir(buildPath);
            }
        } else {
            ftpClient.makeDirectory(buildPath);
            ftpClient.site("CHMOD 755 " + buildPath);
        }

    }
}
 
開發者ID:adamduren,項目名稱:cordova-mover,代碼行數:31,代碼來源:BaseMover.java

示例9: mkdirs

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private void mkdirs(String directory, ChannelSftp c) throws SftpException {
    try {
        SftpATTRS att = c.stat(directory);
        if (att != null && att.isDir()) {
            return;
        }
    } catch (SftpException ex) {
        if (directory.indexOf('/') != -1) {
            mkdirs(directory.substring(0, directory.lastIndexOf('/')), c);
        }
        c.mkdir(directory);
    }
}
 
開發者ID:apache,項目名稱:ant-ivy,代碼行數:14,代碼來源:SFTPRepository.java

示例10: fileExists

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
private boolean fileExists(ChannelSftp sftp, String filePath) throws SftpException {
    boolean found = false;
    SftpATTRS attributes = null;
    try {
        attributes = sftp.stat(filePath);
    } catch (Exception e) {
        found = false;
    }
    if (attributes != null) {
        found = true;
    }
    return found;
}
 
開發者ID:JumpMind,項目名稱:metl,代碼行數:14,代碼來源:SftpDirectory.java

示例11: execute

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
/**
 * Carry out the transfer.
 * @throws IOException on i/o errors
 * @throws JSchException on errors detected by scp
 */
@Override
public void execute() throws IOException, JSchException {
    final ChannelSftp channel = openSftpChannel();
    try {
        channel.connect();
        try {
            final SftpATTRS attrs = channel.stat(remoteFile);
            if (attrs.isDir() && !remoteFile.endsWith("/")) {
                remoteFile = remoteFile + "/";
            }
        } catch (final SftpException ee) {
            // Ignored
        }
        getDir(channel, remoteFile, localFile);
    } catch (final SftpException e) {
        final JSchException schException =
            new JSchException("Could not get '" + remoteFile + "' to '"
                + localFile + "' - " + e.toString());
        schException.initCause(e);
        throw schException;
    } finally {
        if (channel != null) {
            channel.disconnect();
        }
    }
    log("done\n");
}
 
開發者ID:apache,項目名稱:ant,代碼行數:33,代碼來源:ScpFromMessageBySftp.java

示例12: getFileStatus

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
public FileStatus getFileStatus(Path path) throws IOException {
  ChannelSftp channelSftp = null;
  ChannelExec channelExec1 = null;
  ChannelExec channelExec2 = null;
  try {
    channelSftp = this.fsHelper.getSftpChannel();
    SftpATTRS sftpAttrs = channelSftp.stat(HadoopUtils.toUriPath(path));
    FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions());

    channelExec1 = this.fsHelper.getExecChannel("id " + sftpAttrs.getUId());
    String userName = IOUtils.toString(channelExec1.getInputStream());

    channelExec2 = this.fsHelper.getExecChannel("id " + sftpAttrs.getGId());
    String groupName = IOUtils.toString(channelExec2.getInputStream());

    FileStatus fs =
        new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, sftpAttrs.getMTime(), sftpAttrs.getATime(),
            permission, StringUtils.trimToEmpty(userName), StringUtils.trimToEmpty(groupName), path);

    return fs;
  } catch (SftpException e) {
    throw new IOException(e);
  } finally {
    safeDisconnect(channelSftp);
    safeDisconnect(channelExec1);
    safeDisconnect(channelExec2);
  }

}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:31,代碼來源:SftpLightWeightFileSystem.java

示例13: call

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
@Override
public StatInfo call() throws IOException, CancellationException, JSchException, ExecutionException, InterruptedException, SftpException {
    if (!path.startsWith("/")) { //NOI18N
        throw new FileNotFoundException("Path is not absolute: " + path); //NOI18N
    }
    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 activityID = RemoteStatistics.startChannelActivity("statload", path); // NOI18N
            try {
                SftpATTRS attrs = lstat ? cftp.lstat(path) : cftp.stat(path);
                String dirName, baseName;
                int slashPos = path.lastIndexOf('/');
                if (slashPos == 0) {
                    dirName = "";
                    baseName = path.substring(1);
                } else {
                    dirName = path.substring(0, slashPos);
                    baseName = path.substring(slashPos + 1);
                }
                result = createStatInfo(dirName, baseName, 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(activityID);
                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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:67,代碼來源:SftpSupport.java

示例14: checkExistence

import com.jcraft.jsch.ChannelSftp; //導入方法依賴的package包/類
/**
 * Checks the existence for a remote file
 *
 * @param file
 *            to check
 * @param channel
 *            to use
 * @return true if file exists, false otherwise
 */
private boolean checkExistence(String file, ChannelSftp channel) {
    try {
        return channel.stat(file) != null;
    } catch (SftpException ex) {
        return false;
    }
}
 
開發者ID:apache,項目名稱:ant-ivy,代碼行數:17,代碼來源:SFTPRepository.java


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