简体   繁体   English

使用JSch的Java文件传输

[英]Java File Transfer using JSch

I have a Java SFTP Transfer application working fine using a file that is saved on disk. 我有一个Java SFTP Transfer应用程序,可以使用保存在磁盘上的文件正常工作。 I like to change the logic to use a string or stream. 我喜欢改变使用字符串或流的逻辑。 All the information I can find is that it only takes FileInputStream . 我能找到的所有信息是,它仅需要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. 基于此处找到的PaŭloEbermann维护的JSch 0.1.44 (非官方)Javadoc, ChannelSftp具有几种重载的put(...)方法。 So you can provide an InputStream (or any subclass), not just a FileInputStream reference. 因此,您可以提供一个InputStream (或任何子类),而不仅仅是FileInputStream引用。 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 . 例如, put(InputStream src, String dst)会将文件从输入流src上传到dstdst相对于当前远程目录的远程目标文件名

You can also provide the String path to the file you want transferred. 您还可以提供要传输的文件的String路径。 For example, the put(String src, String dst) method with the parameters: 例如,带有参数的put(String src, String dst)方法:

  • src - the local source file name, absolute or relative to the current local directory . src 本地源文件名,绝对或相对于当前本地目录
  • dst - the remote destination file name, absolute or relative to the current remote directory . dst 远程目标文件名,绝对或相对于当前远程目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM