首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSchException找不到消息

JSchException找不到消息
EN

Stack Overflow用户
提问于 2020-06-20 06:44:52
回答 1查看 1K关注 0票数 0

我想知道一些可能导致以下例外情况的原因。我无法在Cannot find message中找到这条消息jsch-0.1.54.jar。有一些直接的消息,如file not found和其他有意义的。但我需要更多关于这个问题的信息,这样我才能找到根本原因。

代码语言:javascript
复制
SftpException while running get ---> 2: Cannot find message [/destination/file.txt]
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2289)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:1741)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:1758)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:786)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:750)
at com.iyi.ftp.SFTP.get(SFTP.java:99)

这是我的呼叫方法。

代码语言:javascript
复制
public boolean get(final String remoteFile, final String localFile) throws JSchException {
    Vector connection = null;
    Session session = null;
    ChannelSftp c = null;
    boolean status = false;
    try {
        connection = this.connect();
        session = connection.get(0);
        c = connection.get(1);
        c.get(remoteFile, localFile);
        status = true;
    }
    catch (JSchException e) {
        SFTP.LGR.warn((Object)("JSchException in SFTP::get() ---> " + FTPFactory.getStackTrace((Throwable)e)));
        throw e;
    }
    catch (SftpException e2) {
        SFTP.LGR.warn((Object)("SftpException while running get ---> " + FTPFactory.getStackTrace((Throwable)e2)));
        throw new JSchException(e2.getMessage());
    }
    catch (CredentialDecryptionException e3) {
        SFTP.LGR.error((Object)"##CredentialDecryptionException##", (Throwable)e3);
        throw new JSchException(e3.getMessage(), (Throwable)e3);
    }
    finally {
        if (c != null) {
            c.quit();
        }
        if (session != null) {
            session.disconnect();
        }
    }
    if (c != null) {
        c.quit();
    }
    if (session != null) {
        session.disconnect();
    }
    return status;
}

这些方法是从jsch-0.1.54.jar获取的,这是一个开源实用程序。

代码语言:javascript
复制
public void get(String src, String dst, final SftpProgressMonitor monitor, final int mode) throws SftpException {
    boolean _dstExist = false;
    String _dst = null;
    try {
        ((MyPipedInputStream)this.io_in).updateReadSide();
        src = this.remoteAbsolutePath(src);
        dst = this.localAbsolutePath(dst);
        final Vector v = this.glob_remote(src);
        final int vsize = v.size();
        if (vsize == 0) {
            throw new SftpException(2, "No such file");
        }
        final File dstFile = new File(dst);
        final boolean isDstDir = dstFile.isDirectory();
        StringBuffer dstsb = null;
        if (isDstDir) {
            if (!dst.endsWith(ChannelSftp.file_separator)) {
                dst += ChannelSftp.file_separator;
            }
            dstsb = new StringBuffer(dst);
        }
        else if (vsize > 1) {
            throw new SftpException(4, "Copying multiple files, but destination is missing or a file.");
        }
        for (int j = 0; j < vsize; ++j) {
            final String _src = v.elementAt(j);
            final SftpATTRS attr = this._stat(_src);
            if (attr.isDir()) {
                throw new SftpException(4, "not supported to get directory " + _src);
            }
            _dst = null;
            if (isDstDir) {
                final int i = _src.lastIndexOf(47);
                if (i == -1) {
                    dstsb.append(_src);
                }
                else {
                    dstsb.append(_src.substring(i + 1));
                }
                _dst = dstsb.toString();
                if (_dst.indexOf("..") != -1) {
                    final String dstc = new File(dst).getCanonicalPath();
                    final String _dstc = new File(_dst).getCanonicalPath();
                    if (_dstc.length() <= dstc.length() || !_dstc.substring(0, dstc.length() + 1).equals(dstc + ChannelSftp.file_separator)) {
                        throw new SftpException(4, "writing to an unexpected file " + _src);
                    }
                }
                dstsb.delete(dst.length(), _dst.length());
            }
            else {
                _dst = dst;
            }
            final File _dstFile = new File(_dst);
            if (mode == 1) {
                final long size_of_src = attr.getSize();
                final long size_of_dst = _dstFile.length();
                if (size_of_dst > size_of_src) {
                    throw new SftpException(4, "failed to resume for " + _dst);
                }
                if (size_of_dst == size_of_src) {
                    return;
                }
            }
            if (monitor != null) {
                monitor.init(1, _src, _dst, attr.getSize());
                if (mode == 1) {
                    monitor.count(_dstFile.length());
                }
            }
            FileOutputStream fos = null;
            _dstExist = _dstFile.exists();
            try {
                if (mode == 0) {
                    fos = new FileOutputStream(_dst);
                }
                else {
                    fos = new FileOutputStream(_dst, true);
                }
                this._get(_src, fos, monitor, mode, new File(_dst).length());
            }
            finally {
                if (fos != null) {
                    fos.close();
                }
            }
        }
    }
    catch (Exception e) {
        if (!_dstExist && _dst != null) {
            final File _dstFile2 = new File(_dst);
            if (_dstFile2.exists() && _dstFile2.length() == 0L) {
                _dstFile2.delete();
            }
        }
        if (e instanceof SftpException) {
            throw (SftpException)e;
        }
        if (e instanceof Throwable) {
            throw new SftpException(4, "", e);
        }
        throw new SftpException(4, "");
    }
}

private SftpATTRS _stat(final byte[] path) throws SftpException {
    try {
        this.sendSTAT(path);
        Header header = new Header();
        header = this.header(this.buf, header);
        final int length = header.length;
        final int type = header.type;
        this.fill(this.buf, length);
        if (type != 105) {
            if (type == 101) {
                final int i = this.buf.getInt();
                this.throwStatusError(this.buf, i);
            }
            throw new SftpException(4, "");
        }
        final SftpATTRS attr = SftpATTRS.getATTR(this.buf);
        return attr;
    }
    catch (Exception e) {
        if (e instanceof SftpException) {
            throw (SftpException)e;
        }
        if (e instanceof Throwable) {
            throw new SftpException(4, "", e);
        }
        throw new SftpException(4, "");
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-22 08:05:24

错误消息来自您的服务器。这确实是非常奇怪的消息,但我假设是一些自定义的SFTP服务器处理一些“消息”而不是普通文件。

因此,该消息基本上转化为传统SFTP服务器的“无法找到文件”错误。甚至错误代码2 (SSH_FX_NO_SUCH_FILE)也支持这一点。

您在remoteFile中的路径可能是错误的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62482581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档