代码之家  ›  专栏  ›  技术社区  ›  Karthi

SFTP Java-管道闭合Jsch异常

  •  3
  • Karthi  · 技术社区  · 7 年前

    我正在研究一种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
    

    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)
    

    我尝试了足够多的探索,但我的问题没有得到一个明确的答案,我想我错过了一些东西。如有任何建议,我们将不胜感激。

     [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,除了

    我仍然认为行中存在错误

    客户登录(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)
    
    2 回复  |  直到 7 年前
        1
  •  8
  •   Bahadir Tasdemir    5 年前

    第二次看你的代码(在我喝咖啡之后,它更好), java.io.IOException: Pipe closed

    你最后的障碍是 在…内 你的for循环。由于无论是否发生异常,始终调用finally块,因此在第一次迭代结束时,finally块始终会断开客户机的连接:

    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();
        }
    }
    

    java.lang.NoSuchFieldError: identities 是由应用程序的另一部分使用不同的JSch版本引起的,正如您根据Maven依赖树放入证据一样。

    在项目中做了一个mvn依赖项:tree-Dverbose(使用jsch 0.1.50),我发现该项目和我在原始帖子中添加了所有日志:尤其是这个:+-org.mule.transports:mule transport sftp:jar:3.4.0:compile[INFO]|+-(com.jcraft:jsch:jar:0.1.44-1:compile-省略,因为与0.1.42冲突)+-(com.jcraft:jsch:jar:0.1.42:compile-省略,因为与0.1.50冲突)[INFO]-com.jcraft:jsch:jar:0.1.50:compile[INFO]

        2
  •  0
  •   Pierre B.    7 年前

    com.jcraft.jsch.JSchException: java.io.IOException: Pipe closed

    另外,请检查ssh服务器日志,您可能会发现一些有用的信息。