2017-08-10 294 views
0

我正在研究java方法将文件从一个位置复制到另一个远程位置。我的代码如下。我尝试使用jsch 0.1.42 & 0.1.50 & 0.1.54SFTP Java - 管道关闭Jsch异常

 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) 

我试图探索不够,我不能得到一个明确的答复我的问题,我想我失去了一些东西。任何建议将不胜感激。

Maven的依赖关系树,当我使用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以外的任何其他JSCH库0.50

我还在行

client.login(sftpUser错误,keyFilePath,NU二);

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) 
+0

'使用JSch 0.1.50可能是由仍然在使用另一JSch版本的应用程序的其他部分时引起NoSuchFieldError'。你确定你重新编译了你的整个代码吗?即'通常,这个错误是由编译器捕获的;这个错误只能在运行时发生,如果一个类的定义发生了不兼容的变化。' 使用JSch 0.1.42时,哪一行正好抛出异常? (显示整个堆栈跟踪可能会有所帮助) –

+0

@PierreB谢谢您的评论。当我使用jsch 01.42时,我编辑了完整的堆栈strace,我发现在\t client.storeFile(inputPath.getName(),bis)行发生错误; 。非常感谢这个建议。 – Karthi

+0

@PierreB。我做了一个mvn依赖项:树 - 在项目中使用jsch 0.1.50),我发现项目和我已经在原始文章中添加了所有日志:特别是:+ - org.mule.transports:mule- transport-sftp:jar:3.4.0:compile [INFO] | + - (com.jcraft:jsch:jar:0.1.44-1:编译 - 省略与0.1.42冲突) + - (com.jcraft:jsch:jar:0.1.42:编译 - 省略冲突0.1.50) [INFO] \ - com.jcraft:jsch:jar:0.1.50:compile [INFO] ---------------------- -------------------------------------------------- [INFO] BUILD SUCCESS – Karthi

回答

2

看你的代码的第二时间(我的咖啡之后,它的更好),java.io.IOException: Pipe closed与JSch 0.1.42有效地通过一个逻辑问题引起的如你所说:

你finally块您for循环。作为一个finally块总是被称为异常是否发生,或者不是你的客户端是由始终断开终于在第一个iteraton结束块:

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循环代码lisibility功能是个好主意;)

java.lang.NoSuchFieldError: identities通过使用不同的JSch版本的应用程序的另一个标准杆引起的,你把证据每Maven的依赖性TRE即

做了MVN依赖性:树-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:罐子:0.1.50:编译[INFO]

0

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

还检查您的SSH服务器日志,你可能有一些有用的东西。

+0

当我使用jsch 0.1.42传递一个小文件列表..在服务器端没有问题。第一个文件被传送到其他机器。问题从第二个文件开始。这是否意味着代码中的任何逻辑问题,连接在处理之前突然关闭? – Karthi

+0

你是对的,再看看你的代码,这似乎是一个逻辑问题。我发布了一个合适的答案。 –