Java File Transfer using JSch

I have a Java SFTP Transfer application working fine using a file that is saved on disk. I like to change the logic to use a string or stream. All the information I can find is that it only takes FileInputStream . Any help would be great.

ChannelSftp c = createSession();
try {
    File f = new File(workingFile);
    c.put(new FileInputStream(f), f.getName());
} catch (Exception e) {
    System.err.println("Storing remote file failed. "+e.toString());
    throw e;
}

Based on the JSch 0.1.44 (unofficial) Javadoc maintained by Paŭlo Ebermann found here, ChannelSftp has several overloaded put(...) methods. So you can provide an InputStream (or any subclass), not just a FileInputStream reference. For example, put(InputStream src, String dst) would upload a file from an input stream src to the dst , which is the remote destination file name, relative to the current remote directory.

You can also provide the String path to the file you want transferred. For example, the put(String src, String dst) method with the parameters:

  • src - the local source file name, absolute or relative to the current local directory.
  • dst - the remote destination file name, absolute or relative to the current remote directory.
  • 链接地址: http://www.djcxy.com/p/78476.html

    上一篇: 在Android / Java中使用JSON / Base64编码文件

    下一篇: 使用JSch的Java文件传输