Java SFTP upload using JSch, but how to overwrite the current file?

后端 未结 1 993
北荒
北荒 2021-02-07 05:28

I am trying to upload two files to a server with SFTP using JSch. It works fine to upload the files if the directory is empty but I want to upload the same file over and over (j

相关标签:
1条回答
  • 2021-02-07 05:59

    I've never used JSch but from the looks of it there are a number of overloaded put methods where one matches your current signature with the addition of a "mode" parameter and there seems to be three static mode parameters in the ChannelSftp class (OVERWRITE = 0, RESUME = 1, APPEND = 2) so you should be able to use:

    channelSftp.put(new FileInputStream(f1), f1.getName(), ChannelSftp.OVERWRITE);

    0 讨论(0)
提交回复
热议问题