Is multipart file upload possible with SFTP JSch library?

…衆ロ難τιáo~ 提交于 2019-12-04 20:38:32

Your question does not really make sense. You seem to make some assumptions that are not true. But it's hard to tell, what those are, as your question is rather sparse.

"Multipart upload" is a term used with other protocols. Those are usually HTTP-based protocols (like S3, REST, etc), as HTTP have problems with uploading large files. For example firewalls between the client and server may not allow an HTTP connection to stay open long enough for an upload of a large file to complete.

That's usually irrelevant for SFTP, for at least two reasons:

  • SFTP uses a persistent connection, contrary to HTTP. So firewalls usually do not limit a length of an SFTP session, as that would break any regular use of the protocol, not only uploads.
  • SFTP transfers (including uploads) are packet-based, contrary to stream-based HTTP. So it's effectively multipart in a way on its own.

    With SFTP, client sends sequence of write requests of arbitrary length. Not one huge data stream like with HTTP. Also those requests can be resumed after an eventual reconnect (what would be an exact equivalent of "multipart upload").

    With JSch library, you can implement the "multipart upload" using ChannelSftp.put method overload that takes offset parameter:

    public OutputStream put(
        String dst, final SftpProgressMonitor monitor, final int mode, long offset)
        throws SftpException{
    

    Or, even easier, you can make use of ChannelSftp.RESUME mode, which takes care of the offset on its own. See also Resume file transfer for a half way failed file transfer or How to reput on JSch SFTP?

    But again, you do not really need "multipart upload" with SFTP. The purpose of the method is to allow resuming a file transfer in case of a (rare) disconnect, not to implement "multipart upload".

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!