SFTP Java - 管道关闭Jsch异常

时间:2017-08-10 15:12:09

标签: java authentication mule sftp 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

时,

Maven依赖树

 [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)

2 个答案:

答案 0 :(得分:4)

第二次查看你的代码(在我的咖啡之后,它更好),java.io.IOException: Pipe closed与JSch 0.1.42实际上是由你建议的逻辑问题引起的:

你的finally块是里面你的for循环。因为始终调用finally块,无论是否发生异常,客户端总是在第一个iteraton末尾的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();
    }
}

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

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

  

做了一个mvn依赖:tree -Dverbose在项目中(使用jsch 0.1.50)我发现该项目和我在原帖中添加了所有日志:特别是:+ - org.mule.transports: mule-transport-sftp:jar:3.4.0:编译[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:编译[INFO]

答案 1 :(得分:0)

看起来像服务器问题。您确定要连接的用户是否具有写入权限?您的SFTP服务器是否可以访问?看一下这篇文章:com.jcraft.jsch.JSchException: java.io.IOException: Pipe closed

同时检查你的ssh服务器日志,你可能会有一些有用的东西。