本文整理汇总了Java中com.jcraft.jsch.ChannelSftp.SSH_FX_NO_SUCH_FILE属性的典型用法代码示例。如果您正苦于以下问题:Java ChannelSftp.SSH_FX_NO_SUCH_FILE属性的具体用法?Java ChannelSftp.SSH_FX_NO_SUCH_FILE怎么用?Java ChannelSftp.SSH_FX_NO_SUCH_FILE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.jcraft.jsch.ChannelSftp
的用法示例。
在下文中一共展示了ChannelSftp.SSH_FX_NO_SUCH_FILE属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendDirectoryToRemote
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: fastExistsFile
protected boolean fastExistsFile(String name) throws GenericFileOperationFailedException {
LOG.trace("fastExistsFile({})", name);
try {
@SuppressWarnings("rawtypes")
Vector files = channel.ls(name);
if (files == null) {
return false;
}
return files.size() >= 1;
} 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);
}
}
示例3: createRemotePath
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);
}
}
}
示例4: getMetaData
public ExternalResourceMetaData getMetaData(URI uri, boolean revalidate) {
LockableSftpClient sftpClient = sftpClientFactory.createSftpClient(uri, credentials);
try {
SftpATTRS attributes = sftpClient.getSftpClient().lstat(uri.getPath());
return attributes != null ? toMetaData(uri, attributes) : null;
} catch (com.jcraft.jsch.SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
return null;
}
throw ResourceExceptions.getFailed(uri, e);
} finally {
sftpClientFactory.releaseSftpClient(sftpClient);
}
}
示例5: convertException
private Exception convertException(Exception e) {
if (SftpException.class.isAssignableFrom(e.getClass()) )
{
SftpException sftpEx = (SftpException)e;
if (sftpEx.id == ChannelSftp.SSH_FX_NO_SUCH_FILE)
return new FileNotFoundException(sftpEx.getMessage());
}
return e;
}
示例6: existsFile
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);
}
}
示例7: ignoreCannotRetrieveFile
@Override
protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange, Exception cause) {
if (getEndpoint().getConfiguration().isIgnoreFileNotFoundOrPermissionError()) {
SftpException sftp = ObjectHelper.getException(SftpException.class, cause);
if (sftp != null) {
return sftp.id == ChannelSftp.SSH_FX_NO_SUCH_FILE || sftp.id == ChannelSftp.SSH_FX_PERMISSION_DENIED;
}
}
return super.ignoreCannotRetrieveFile(name, exchange, cause);
}
示例8: getMetaData
public ExternalResourceMetaData getMetaData(URI uri) throws IOException {
LockableSftpClient sftpClient = sftpClientFactory.createSftpClient(uri, credentials);
try {
SftpATTRS attributes = sftpClient.getSftpClient().lstat(uri.getPath());
return attributes != null ? toMetaData(uri, attributes) : null;
} catch (com.jcraft.jsch.SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
return null;
}
throw new SftpException(String.format("Could not get resource '%s'.", uri), e);
} finally {
sftpClientFactory.releaseSftpClient(sftpClient);
}
}
示例9: execute
@Override
protected void execute() throws SftpResult, JSchException {
ChannelSftp ch = channel();
try {
ch.rm(path);
throw new SftpResult(true);
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
throw new SftpResult(false);
}
throw new SftpError(e, "Error putting file[%s]", path);
} finally {
release(ch);
}
}
示例10: execute
@Override
protected void execute() throws SftpResult, JSchException {
ChannelSftp ch = channel();
try {
ch.mkdir(path);
throw new SftpResult(true);
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
throw new SftpResult(false);
}
throw new SftpError(e, "Error putting file[%s]", path);
} finally {
release(ch);
}
}
示例11: execute
@Override
protected void execute() throws SftpResult, JSchException {
ChannelSftp ch = channel();
try {
ch.rmdir(path);
throw new SftpResult(true);
} catch (SftpException e) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
throw new SftpResult(false);
}
throw new SftpError(e, "Error putting file[%s]", path);
} finally {
release(ch);
}
}
示例12: statSelf
/**
* Fetches file attrs from server.
*/
private void statSelf() throws Exception
{
ChannelSftp channel = fileSystem.getChannel();
try
{
setStat(channel.stat(relPath));
}
catch (final SftpException e)
{
try
{
// maybe the channel has some problems, so recreate the channel and retry
if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE)
{
channel.disconnect();
channel = fileSystem.getChannel();
setStat(channel.stat(relPath));
}
else
{
// Really does not exist
attrs = null;
}
}
catch (final SftpException e2)
{
// TODO - not strictly true, but jsch 0.1.2 does not give us
// enough info in the exception. Should be using:
// if ( e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE )
// However, sometimes the exception has the correct id, and
// sometimes
// it does not. Need to look into why.
// Does not exist
attrs = null;
}
}
finally
{
fileSystem.putChannel(channel);
}
}
示例13: doGetInputStream
/**
* Creates an input stream to read the file content from.
*/
@Override
protected InputStream doGetInputStream() throws Exception
{
// VFS-113: avoid npe
synchronized (fileSystem)
{
final ChannelSftp channel = fileSystem.getChannel();
try
{
// return channel.get(getName().getPath());
// hmmm - using the in memory method is soooo much faster ...
// TODO - Don't read the entire file into memory. Use the
// stream-based methods on ChannelSftp once they work properly
/*
final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
channel.get(relPath, outstr);
outstr.close();
return new ByteArrayInputStream(outstr.toByteArray());
*/
InputStream is;
try
{
// VFS-210: sftp allows to gather an input stream even from a directory and will
// fail on first read. So we need to check the type anyway
if (!getType().hasContent())
{
throw new FileSystemException("vfs.provider/read-not-file.error", getName());
}
is = channel.get(relPath);
}
catch (SftpException e)
{
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE)
{
throw new FileNotFoundException(getName());
}
throw new FileSystemException(e);
}
return new SftpInputStream(channel, is);
}
finally
{
// fileSystem.putChannel(channel);
}
}
}
示例14: mightBrokeSftpChannel
/**
* If an sftp exception occurs, a question arises, whether we should call ChannelSftp.quit().
* On one hane, *not* calling quit can lead to infinite 4: errors.
* On the other hand, there might be quite standard situations like file not exist or permission denied,
* which do not require quitting the channel.
* This method distinguishes the former and the latter cases.
*/
public static boolean mightBrokeSftpChannel(SftpException e) {
// Or should it be just return e.id == ChannelSftp.SSH_FX_FAILURE ?
// well, let's be conservative
return e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE && e.id != ChannelSftp.SSH_FX_PERMISSION_DENIED;
}