-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sftpChannel怎么增加上传时的缓冲区大小 #8
Comments
试试
|
这个连个方法都是私有方法,你的是意思通过Method反射调用吗?
…------------------ 原始邮件 ------------------
发件人: "gaoxingliang/JSch" ***@***.***>;
发送时间: 2022年5月23日(星期一) 下午4:26
***@***.***>;
***@***.******@***.***>;
主题: Re: [gaoxingliang/JSch] sftpChannel怎么增加上传时的缓冲区大小 (Issue #8)
试试
setLocalPacketSize & setRemotePacketSize
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
无效哦,还是之前的文件快的大小
…------------------ 原始邮件 ------------------
发件人: "gaoxingliang/JSch" ***@***.***>;
发送时间: 2022年5月23日(星期一) 下午4:26
***@***.***>;
***@***.******@***.***>;
主题: Re: [gaoxingliang/JSch] sftpChannel怎么增加上传时的缓冲区大小 (Issue #8)
试试
setLocalPacketSize & setRemotePacketSize
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
贴下你的测试代码看看呢 |
我的目的是适当增加发送缓冲区大小,提升上传速度。我不太了解sftp协议底层,不知道是不是协议底层就是如此限制的。
##版本
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
##代码
public class ApplicationTest {
@test
public void test_001() {
Path path = Paths.get("E:\\Unit\\abcd.pdf");
String remote = StringUtils.buildRemotePath("pdf");
try {
JSch jsch = new JSch();
Session session = jsch.getSession("root", "10.1.227.207", 3370);
session.setPassword("123456");
session.setConfig("StrictHostKeyChecking", "no");
session.connect(1000 * 5);
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect(1000 * 5);
Method[] methods = channel.getClass().getSuperclass().getSuperclass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
if ("setRemotePacketSize".equals(methods[i].getName()) && "setLocalPacketSize".equals(methods[i].getName())) {
methods[i].setAccessible(true);
methods[i].invoke(channel, 1024 * 10 * 10);
System.out.println(methods[i].getName());
}
}
mkdir(channel, StringUtils.getFilePath(remote));
try (InputStream is = Files.newInputStream(path)) {
channel.put(is, StringUtils.getFileName(remote), new SftpProgressMonitor() {
@OverRide
public void init(int op, String src, String dest, long max) {
System.out.println(op);
System.out.println(src);
System.out.println(dest);
System.out.println(max);
}
@OverRide
public boolean count(long count) {
if (count < BufferUtil.KB) {
System.out.println(String.format("SFTP,文件上传,文件大小:%s B", count));
} else if (count > BufferUtil.KB && count < BufferUtil.MB) {
System.out.println(String.format("SFTP,文件上传,文件大小:%s KB", count * 1.0 / BufferUtil.KB));
} else if (count > BufferUtil.MB && count < BufferUtil.GB) {
System.out.println(String.format("SFTP,文件上传,文件大小:%s MB", count * 1.0 / BufferUtil.MB));
} else {
System.out.println(String.format("SFTP,文件上传,文件大小:%s GB", count * 1.0 / BufferUtil.GB));
}
return true;
}
@OverRide
public void end() {
System.out.println("SFTP,文件上传,完成");
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void mkdir(ChannelSftp channel, String path) throws SftpException {
if (StringUtils.isEmpty(path)) {
return;
}
int index = path.indexOf("/");
if (-1 == index) {
try {
channel.lstat(path);
} catch (Exception e) {
channel.mkdir(path);
}
channel.cd(path);
} else {
String dir = path.substring(0, index);
if (StringUtils.isEmpty(dir)) {
mkdir(channel, path.substring(index + 1));
}
try {
channel.lstat(dir);
} catch (Exception e) {
channel.mkdir(dir);
}
channel.cd(dir);
mkdir(channel, path.substring(index + 1));
}
}
}
##结果
…------------------ 原始邮件 ------------------
发件人: "gaoxingliang/JSch" ***@***.***>;
发送时间: 2022年5月24日(星期二) 上午10:09
***@***.***>;
***@***.******@***.***>;
主题: Re: [gaoxingliang/JSch] sftpChannel怎么增加上传时的缓冲区大小 (Issue #8)
贴下你的测试代码看看呢
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: