SFTP Java-管道关闭Jsch异常 [英] SFTP Java - Pipe closed Jsch Exception

查看:41
本文介绍了SFTP Java-管道关闭Jsch异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种将文件从一个位置复制到另一个远程位置的Java方法。我的代码如下所示。我尝试使用jsch 0.1.42&;0.1.50&;0.1.54

      public static void processFiles(ArrayList<String> FilesToBeCopied, String destFilePath) throws IOException {
        SftpClient client = new SftpClient("karthick");
        String keyFilePath = "/ab/c/d/id_rsa";
        String sftpUser = "karthickkb";
        client.login(sftpUser, keyFilePath, null);
        client.changeWorkingDirectory(destFilePath);
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        FSDataInputStream fsdisPath = null;
        String filePath = null;
        for (String sourcefilePath : FilesToBeCopied) {
            try {
                filePath = sourcefilePath;
                Path inputPath = new Path(filePath);
                fsdisPath = fs.open(inputPath);
                BufferedInputStream bis = new BufferedInputStream(fsdisPath);
                client.storeFile(inputPath.getName(), bis);
                fsdisPath.close();
                fsdisPath = null;
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                try {
                    if (client != null) {
                        client.disconnect();


        }
                if (fsdisPath != null) {
                    fsdisPath.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

}

}
我使用Jsch 0.1.42时的错误代码是 使用jsch 0.1.42时收到以下错误代码。

     java.io.IOException: java.io.IOException: Pipe closed
    at org.mule.transport.sftp.SftpClient.storeFile(SftpClient.java:390)
    at karthickArchive.archiveMigration.sftpFileUtil.processFiles(sftpFileUtil.java:58)
    at karthickArchive.archiveMigration.getFileUtility.main  (getFileUtility.java:69)

     17/08/14 07:06:41 ERROR sftp.SftpClient: Error writing data over SFTP service, error was: java.io.IOException: Pipe closed
    4: java.io.IOException: Pipe closed
    at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:578)
    at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:439)
    at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:406)
    at org.mule.transport.sftp.SftpClient.storeFile(SftpClient.java:385)
    at karthickArchive.archiveMigration.sftpFileUtil.processFiles(sftpFileUtil.java:58)
    at karthickArchive.archiveMigration.getFileUtility.main(getFileUtility.java:69)
    Caused by: java.io.IOException: Pipe closed
    at java.io.PipedInputStream.read(PipedInputStream.java:308)
    at java.io.PipedInputStream.read(PipedInputStream.java:378)
    at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2325)
    at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2351)
    at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:474)
    ... 5 mor

当我使用jsch 0.1.50时,错误如下

Exception in thread "main" java.lang.NoSuchFieldError: identities
    at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:39)
    at com.jcraft.jsch.Session.connect(Session.java:463)
    at com.jcraft.jsch.Session.connect(Session.java:183)

我尝试了足够多的探索,但我无法为我的问题找到明确的答案,我想我遗漏了一些东西。任何建议都将不胜感激。

使用jsch 0.1.50时维护依赖关系树

 [INFO] Scanning for projects...
 [INFO]                                                                         
 [INFO] ------------------------------------------------------------------------
 [INFO] Building archiveMigration 0.0.1-SNAPSHOT
 [INFO] ------------------------------------------------------------------------
 [INFO] 
 [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ archiveMigration ---
 [INFO] tdiArchive:archiveMigration:jar:0.0.1-SNAPSHOT
 [INFO] +- org.apache.hadoop:hadoop-hdfs:jar:2.5.0-cdh5.3.2:compile
 [INFO] |  +- com.google.guava:guava:jar:11.0.2:compile
 [INFO] |  |  - (com.google.code.findbugs:jsr305:jar:1.3.9:compile - omitted for duplicate)
 [INFO] |  +- org.mortbay.jetty:jetty:jar:6.1.26.cloudera.4:compile
 [INFO] |  |  - (org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.4:compile - omitted for duplicate)
 [INFO] |  +- org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.4:compile
 [INFO] |  +- com.sun.jersey:jersey-core:jar:1.9:compile
 [INFO] |  +- com.sun.jersey:jersey-server:jar:1.9:compile
 [INFO] |  |  +- asm:asm:jar:3.1:compile
 [INFO] |  |  - (com.sun.jersey:jersey-core:jar:1.9:compile - omitted for duplicate)
 [INFO] |  +- commons-cli:commons-cli:jar:1.2:compile
 [INFO] |  +- commons-codec:commons-codec:jar:1.4:compile
 [INFO] |  +- commons-io:commons-io:jar:2.4:compile
 [INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
 [INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile
 [INFO] |  +- commons-daemon:commons-daemon:jar:1.0.13:compile
 [INFO] |  +- javax.servlet.jsp:jsp-api:jar:2.1:compile
 [INFO] |  +- log4j:log4j:jar:1.2.17:compile
 [INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
 [INFO] |  +- javax.servlet:servlet-api:jar:2.5:compile
 [INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
 [INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
 [INFO] |  |  - (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
 [INFO] |  +- tomcat:jasper-runtime:jar:5.5.23:compile
 [INFO] |  |  +- (javax.servlet:servlet-api:jar:2.4:compile - omitted for conflict with 2.5)
 [INFO] |  |  - commons-el:commons-el:jar:1.0:compile
 [INFO] |  |     - (commons-logging:commons-logging:jar:1.0.3:compile - omitted for conflict with 1.1.3)
 [INFO] |  +- xmlenc:xmlenc:jar:0.52:compile
 [INFO] |  - io.netty:netty:jar:3.6.2.Final:compile
 [INFO] +- org.apache.hadoop:hadoop-common:jar:2.5.0-cdh5.3.2:compile
 [INFO] |  +- org.apache.hadoop:hadoop-annotations:jar:2.5.0-cdh5.3.2:compile
 [INFO] |  |  - jdk.tools:jdk.tools:jar:1.6:system
 [INFO] |  +- (com.google.guava:guava:jar:11.0.2:compile - omitted for duplicate)
 [INFO] |  +- (commons-cli:commons-cli:jar:1.2:compile - omitted for duplicate)
 [INFO] |  +- org.apache.commons:commons-math3:jar:3.1.1:compile
 [INFO] |  +- (xmlenc:xmlenc:jar:0.52:compile - omitted for duplicate)
 [INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
 [INFO] |  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for conflict with 1.1.3)
 [INFO] |  |  - (commons-codec:commons-codec:jar:1.2:compile - omitted for conflict with 1.4)
 [INFO] |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
 [INFO] |  +- (commons-io:commons-io:jar:2.4:compile - omitted for duplicate)
 [INFO] |  +- commons-net:commons-net:jar:3.1:compile
 [INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
 [INFO] |  +- (javax.servlet:servlet-api:jar:2.5:compile - omitted for duplicate)
 [INFO] |  +- (org.mortbay.jetty:jetty:jar:6.1.26.cloudera.4:compile - omitted for duplicate)
 [INFO] |  +- (org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.4:compile - omitted for duplicate)
 [INFO] |  +- (com.sun.jersey:jersey-core:jar:1.9:compile - omitted for duplicate)
 [INFO] |  +- com.sun.jersey:jersey-json:jar:1.9:compile
 [INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
 [INFO] |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
 [INFO] |  |  |  - javax.xml.bind:jaxb-api:jar:2.2.2:compile
 [INFO] |  |  |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
 [INFO] |  |  |     - (javax.activation:activation:jar:1.1:compile - omitted for conflict with 1.1-osgi)
 [INFO] |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
 [INFO] |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  |  - (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  +- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
 [INFO] |  |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  |  - (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  - (com.sun.jersey:jersey-core:jar:1.9:compile - omitted for duplicate)
 [INFO] |  +- (com.sun.jersey:jersey-server:jar:1.9:compile - omitted for duplicate)
 [INFO] |  +- tomcat:jasper-compiler:jar:5.5.23:runtime
 [INFO] |  +- (tomcat:jasper-runtime:jar:5.5.23:runtime - omitted for duplicate)
 [INFO] |  +- (javax.servlet.jsp:jsp-api:jar:2.1:runtime - omitted for duplicate)
 [INFO] |  +- (commons-el:commons-el:jar:1.0:compile - scope updated from runtime; omitted for duplicate)
 [INFO] |  +- (commons-logging:commons-logging:jar:1.1.3:compile - omitted for duplicate)
 [INFO] |  +- (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
 [INFO] |  +- net.java.dev.jets3t:jets3t:jar:0.9.0:compile
 [INFO] |  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
 [INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
 [INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
 [INFO] |  |  |  - (org.apache.httpcomponents:httpcore:jar:4.1.2:compile - omitted for duplicate)
 [INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
 [INFO] |  |  - com.jamesmurty.utils:java-xmlbuilder:jar:0.4:compile
 [INFO] |  +- (commons-lang:commons-lang:jar:2.6:compile - omitted for duplicate)
 [INFO] |  +- commons-configuration:commons-configuration:jar:1.6:compile
 [INFO] |  |  +- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for duplicate)
 [INFO] |  |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.6)
 [INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
 [INFO] |  |  +- commons-digester:commons-digester:jar:1.8:compile
 [INFO] |  |  |  +- (commons-beanutils:commons-beanutils:jar:1.7.0:compile - omitted for conflict with 1.8.0)
 [INFO] |  |  |  - (commons-logging:commons-logging:jar:1.1:compile - omitted for conflict with 1.1.3)
 [INFO] |  |  - commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
 [INFO] |  |     - (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.1.3)
 [INFO] |  +- org.slf4j:slf4j-api:jar:1.7.5:compile
 [INFO] |  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:compile - scope updated from runtime; omitted for duplicate)
 [INFO] |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile - omitted for duplicate)
 [INFO] |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile - omitted for duplicate)
 [INFO] |  +- org.apache.avro:avro:jar:1.7.6-cdh5.3.2:compile
 [INFO] |  |  +- (org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  +- (org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile - omitted for conflict with 1.8.8)
 [INFO] |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
 [INFO] |  |  +- org.xerial.snappy:snappy-java:jar:1.0.5:compile
 [INFO] |  |  +- (org.apache.commons:commons-compress:jar:1.4.1:compile - omitted for duplicate)
 [INFO] |  |  - (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for conflict with 1.7.5)
 [INFO] |  +- (com.google.protobuf:protobuf-java:jar:2.5.0:compile - omitted for duplicate)
 [INFO] |  +- com.google.code.gson:gson:jar:2.2.4:compile
 [INFO] |  +- org.apache.hadoop:hadoop-auth:jar:2.5.0-cdh5.3.2:compile
 [INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  +- (commons-codec:commons-codec:jar:1.4:compile - omitted for duplicate)
 [INFO] |  |  +- (log4j:log4j:jar:1.2.17:runtime - omitted for duplicate)
 [INFO] |  |  +- (org.slf4j:slf4j-log4j12:jar:1.7.5:runtime - omitted for duplicate)
 [INFO] |  |  +- (org.apache.httpcomponents:httpclient:jar:4.2.5:compile - omitted for conflict with 4.1.2)
 [INFO] |  |  +- org.apache.directory.server:apacheds-kerberos-codec:jar:2.0.0-M15:compile
 [INFO] |  |  |  +- org.apache.directory.server:apacheds-i18n:jar:2.0.0-M15:compile
 [INFO] |  |  |  |  - (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  |  +- org.apache.directory.api:api-asn1-api:jar:1.0.0-M20:compile
 [INFO] |  |  |  |  - (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  |  +- org.apache.directory.api:api-util:jar:1.0.0-M20:compile
 [INFO] |  |  |  |  - (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  |  - (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  +- (org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.3.2:compile - omitted for duplicate)
 [INFO] |  |  - org.apache.curator:curator-framework:jar:2.6.0:compile
 [INFO] |  |     +- (org.apache.curator:curator-client:jar:2.6.0:compile - omitted for duplicate)
 [INFO] |  |     +- (org.apache.zookeeper:zookeeper:jar:3.4.6:compile - omitted for conflict with 3.4.5-cdh5.3.2)
 [INFO] |  |     - (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 11.0.2)
 [INFO] |  +- (com.jcraft:jsch:jar:0.1.42:compile - omitted for conflict with 0.1.50)
 [INFO] |  +- org.apache.curator:curator-client:jar:2.6.0:compile
 [INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.6:compile - omitted for conflict with 1.7.5)
 [INFO] |  |  +- (org.apache.zookeeper:zookeeper:jar:3.4.6:compile - omitted for conflict with 3.4.5-cdh5.3.2)
 [INFO] |  |  - (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 11.0.2)
 [INFO] |  +- org.apache.curator:curator-recipes:jar:2.6.0:compile
 [INFO] |  |  +- (org.apache.curator:curator-framework:jar:2.6.0:compile - omitted for duplicate)
 [INFO] |  |  +- (org.apache.zookeeper:zookeeper:jar:3.4.6:compile - omitted for conflict with 3.4.5-cdh5.3.2)
 [INFO] |  |  - (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 11.0.2)
 [INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
 [INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.3.2:compile
 [INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
 [INFO] |  |  |  +- (org.slf4j:slf4j-api:jar:1.7.5:compile - omitted for duplicate)
 [INFO] |  |  |  - (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
 [INFO] |  |  - (log4j:log4j:jar:1.2.17:compile - omitted for duplicate)
 [INFO] |  - org.apache.commons:commons-compress:jar:1.4.1:compile
 [INFO] |     - org.tukaani:xz:jar:1.0:compile
 [INFO] +- org.mule.transports:mule-transport-sftp:jar:3.4.0:compile
 [INFO] |  +- (com.jcraft:jsch:jar:0.1.44-1:compile - omitted for conflict with 0.1.42)
 [INFO] |  +- org.mule:mule-core:jar:3.4.0:compile
 [INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
 [INFO] |  |  +- org.safehaus.jug:jug:jar:asl:2.0.0:compile
 [INFO] |  |  +- (commons-cli:commons-cli:jar:1.2:compile - omitted for duplicate)
 [INFO] |  |  +- (commons-collections:commons-collections:jar:3.2.1:compile - omitted for duplicate)
 [INFO] |  |  +- (commons-io:commons-io:jar:1.4:compile - omitted for conflict with 2.4)
 [INFO] |  |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.6)
 [INFO] |  |  +- commons-pool:commons-pool:jar:1.5.3:compile
 [INFO] |  |  +- javax.activation:activation:jar:1.1-osgi:compile
 [INFO] |  |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
 [INFO] |  |  +- org.apache.geronimo.specs:geronimo-j2ee-connector_1.5_spec:jar:1.1-osgi:compile
 [INFO] |  |  +- javax.annotation:jsr250-api:jar:1.0:compile
 [INFO] |  |  +- org.slf4j:jcl-over-slf4j:jar:1.6.1:compile
 [INFO] |  |  |  - (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.7.5)
 [INFO] |  |  +- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.7.5)
 [INFO] |  |  +- (org.slf4j:slf4j-log4j12:jar:1.6.1:compile - omitted for conflict with 1.7.5)
 [INFO] |  |  +- (log4j:log4j:jar:1.2.16:compile - omitted for conflict with 1.2.17)
 [INFO] |  |  +- (asm:asm:jar:3.1:compile - omitted for duplicate)
 [INFO] |  |  +- asm:asm-commons:jar:3.1:compile
 [INFO] |  |  |  - asm:asm-tree:jar:3.1:compile
 [INFO] |  |  |     - (asm:asm:jar:3.1:compile - omitted for duplicate)
 [INFO] |  |  +- org.mvel:mvel2:jar:2.1.3.Final:compile
 [INFO] |  |  +- org.jgrapht:jgrapht-jdk1.5:jar:0.7.3:compile
 [INFO] |  |  - org.mule.common:mule-common:jar:0.11.0:compile
 [INFO] |  - (org.mule.transports:mule-transport-file:jar:3.4.0:compile - omitted for duplicate)
 [INFO] +- org.mule.transports:mule-transport-file:jar:3.4.0:compile
 [INFO] |  - org.mule.modules:mule-module-spring-config:jar:3.4.0:compile
 [INFO] |     +- (org.mule:mule-core:jar:3.4.0:compile - omitted for duplicate)
 [INFO] |     +- org.mule.modules:mule-module-annotations:jar:3.4.0:compile
 [INFO] |     |  +- (org.mule:mule-core:jar:3.4.0:compile - omitted for duplicate)
 [INFO] |     |  - cglib:cglib-nodep:jar:2.2:compile
 [INFO] |     +- org.springframework:spring-context:jar:3.2.1.RELEASE:compile
 [INFO] |     |  +- org.springframework:spring-beans:jar:3.2.1.RELEASE:compile
 [INFO] |     |  |  - (org.springframework:spring-core:jar:3.2.1.RELEASE:compile - omitted for duplicate)
 [INFO] |     |  +- org.springframework:spring-aop:jar:3.2.1.RELEASE:compile
 [INFO] |     |  |  +- (org.springframework:spring-beans:jar:3.2.1.RELEASE:compile - omitted for duplicate)
 [INFO] |     |  |  - (org.springframework:spring-core:jar:3.2.1.RELEASE:compile - omitted for duplicate)
 [INFO] |     |  +- org.springframework:spring-expression:jar:3.2.1.RELEASE:compile
 [INFO] |     |  |  - (org.springframework:spring-core:jar:3.2.1.RELEASE:compile - omitted for duplicate)
 [INFO] |     |  - org.springframework:spring-core:jar:3.2.1.RELEASE:compile
 [INFO] |     +- dom4j:dom4j:jar:1.6.1-osgi:compile
 [INFO] |     - jaxen:jaxen:jar:1.1.1:compile
 [INFO] |        +- (jaxen:jaxen:jar:1.1-beta-6:compile - omitted for cycle)
 [INFO] |        +- (dom4j:dom4j:jar:1.6.1:compile - omitted for conflict with 1.6.1-osgi)
 [INFO] |        +- (jaxen:jaxen:jar:1.0-FCS:compile - omitted for cycle)
 [INFO] |        - jdom:jdom:jar:1.0:compile
 [INFO] - com.jcraft:jsch:jar:0.1.50:compile
 [INFO] -------------------------------------------------------------------- 
 [INFO] BUILD SUCCESS
 [INFO] -------------------------------------------------------------------- 
 [INFO] Total time: 7.989 s
 [INFO] Finished at: 2017-08-14T18:02:29+05:30
 [INFO] Final Memory: 18M/356M
 [INFO] --------------------------------------------------------------------      ----

删除所有其他JSCH库之后,下面是我的maven,除了0.1.50

之外,我没有看到任何其他JSCH库

我仍然在行中出现错误

client.login(sftpUser,keyFilePath,null);

 Actual Log:Exception in thread "main" java.lang.NoSuchFieldError: identities
    at com.jcraft.jsch.UserAuthPublicKey.start(UserAuthPublicKey.java:39)
    at com.jcraft.jsch.Session.connect(Session.java:463)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at org.mule.transport.sftp.SftpClient.login(SftpClient.java:178)
    at karthickArchive.archiveMigration.sftpFileUtil.processFiles(sftpFileUtil.java:46)
    at karthickArchive.archiveMigration.getFileUtility.main(getFileUtility.java:69)

推荐答案

再次查看您的代码(就在我喝完咖啡之后,这样更好),java.io.IOException: Pipe closed使用JSCH 0.1.42实际上是由您建议的逻辑问题引起的:

您的最终挡路您的for循环中。作为最后一个挡路,无论是否发生异常,您的客户端总是在第一次迭代结束时被最后一个挡路断开连接:

for(...){
    try{
        ...
    }catch(...){
        ...
    }finally{
        # this finally block is inside your for loop
        # finally block is always called whether an exception occur or not
        # on the first iteration, this is called and close your client
        try{
            if(client!=null){
                # nope, it will close the client for next iteration!
                client.disconnect();
            }if(fsdisPath!=null){
                # good to close this however
                fsdisPath.close();
            }
        }catch(Exceptionex){
            ex.printStackTrace();
        }
    }
}

相反,您应该拥有如下内容:

try {
    for(...){
        try{
            ...
        }catch(...){
            ...
        }finally{
            try{
                if(fsdisPath!=null){
                    fsdisPath.close();
                }
            }catch(Exceptionex){
                ex.printStackTrace();
            }
        }
    }
} finally {
    if(client!=null){
        client.disconnect();
    }
}

将for循环作为代码可见性的函数也可能是个好主意;)

java.lang.NoSuchFieldError: identities是由应用程序的另一部分使用不同的JSch版本引起的,因为您根据Maven依赖关系树进行了验证。

在项目(使用jsch 0.1.50)中执行了mvn依赖:tree-dVerose,我发现项目和我已经添加了原始帖子中的所有日志:特别是这个:+-org.mule.transports:mule-transport-sftp:jar:3.4.0:compile[信息]|+-(com.jcraft:jsch:jar:0.1.44-1:COMPILE-由于与0.1.42冲突而省略)+-(com.jcraft:JSCH:JAR:0.1.42:COMPILE-因与0.1.50冲突而省略)[信息]-com.jcraft:jsch:jar:0.1.50:编译[信息]

这篇关于SFTP Java-管道关闭Jsch异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆