SFTP JSch库可以上传多部分文件吗? [英] Is multipart file upload possible with SFTP JSch library?

查看:209
本文介绍了SFTP JSch库可以上传多部分文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传一个非常大的文件,其大小可以为 1 GB .是否可以将其上传到SFTP服务器或从SFTP服务器下载?我正在使用JSch库.

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.

分段上传" 是与其他协议一起使用的术语.这些通常是基于HTTP的协议(例如S3,REST等),因为HTTP在上传大文件时遇到问题.例如,客户端和服务器之间的防火墙可能不允许HTTP连接保持打开状态足够长的时间,以至无法完成大文件的上传.

"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.

这通常与SFTP无关,原因至少有两个:

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

  • 与HTTP相反,SFTP使用持久连接.因此,防火墙通常不限制SFTP会话的长度,因为那样会破坏协议的常规使用,而不仅限于上传.
  • 与基于流的HTTP相反,SFTP传输(包括上载)是基于数据包的.因此,它以一种独立的方式实际上是多部分的.

  • 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.

使用SFTP,客户端发送任意长度的写请求序列.没有一个像HTTP那样庞大的数据流.最终重新连接后,这些请求也可以恢复(这完全等同于分段上传" ).

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").

使用JSch库,您可以使用

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{

或者,甚至更容易,您可以使用ChannelSftp.RESUME模式,该模式可以自己处理偏移量.另请参见恢复文件传输以中途失败进行文件传输

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?

但是同样,您实际上不需要使用SFTP的分段上传" . ChannelSftp.RESUME模式的目的是允许在(很少)断开连接的情况下恢复文件传输,而不是实现分段上传" .

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

这篇关于SFTP JSch库可以上传多部分文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆