I want to upload a very big size file which can be of size 1 GB. Is it possible to upload or download it to/from SFTP server? I am using JSch library.
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 takesoffset
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".
来源:https://stackoverflow.com/questions/50903133/is-multipart-file-upload-possible-with-sftp-jsch-library