本文整理汇总了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("..");
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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");
}
示例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);
}
}
示例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;
}
示例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;
}
}