mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复多线程下Sftp中Channel关闭的问题
This commit is contained in:
parent
68daef704e
commit
e8c1f7ad7b
@ -33,6 +33,7 @@
|
|||||||
* 【json 】 修复JSONBeanParser在遇到List时没有被正确递归问题(issue#I7M2GZ@Gitee)
|
* 【json 】 修复JSONBeanParser在遇到List时没有被正确递归问题(issue#I7M2GZ@Gitee)
|
||||||
* 【core 】 修复VersionComparator对1.0.3及1.0.2a比较有误的问题(pr#1043@Gitee)
|
* 【core 】 修复VersionComparator对1.0.3及1.0.2a比较有误的问题(pr#1043@Gitee)
|
||||||
* 【core 】 修复IOS系统下,chrome 浏览器的解析规则有误(pr#1044@Gitee)
|
* 【core 】 修复IOS系统下,chrome 浏览器的解析规则有误(pr#1044@Gitee)
|
||||||
|
* 【extra 】 修复多线程下Sftp中Channel关闭的问题(issue#I7OHIB@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.20(2023-06-16)
|
# 5.8.20(2023-06-16)
|
||||||
|
@ -233,6 +233,9 @@ public class Sftp extends AbstractFtp {
|
|||||||
* @since 4.1.14
|
* @since 4.1.14
|
||||||
*/
|
*/
|
||||||
public ChannelSftp getClient() {
|
public ChannelSftp getClient() {
|
||||||
|
if(false == this.channel.isConnected()){
|
||||||
|
init();
|
||||||
|
}
|
||||||
return this.channel;
|
return this.channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +247,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
@Override
|
@Override
|
||||||
public String pwd() {
|
public String pwd() {
|
||||||
try {
|
try {
|
||||||
return channel.pwd();
|
return getClient().pwd();
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -258,7 +261,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public String home() {
|
public String home() {
|
||||||
try {
|
try {
|
||||||
return channel.getHome();
|
return getClient().getHome();
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -339,7 +342,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
public List<LsEntry> lsEntries(String path, Filter<LsEntry> filter) {
|
public List<LsEntry> lsEntries(String path, Filter<LsEntry> filter) {
|
||||||
final List<LsEntry> entryList = new ArrayList<>();
|
final List<LsEntry> entryList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
channel.ls(path, entry -> {
|
getClient().ls(path, entry -> {
|
||||||
final String fileName = entry.getFilename();
|
final String fileName = entry.getFilename();
|
||||||
if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
|
if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
|
||||||
if (null == filter || filter.accept(entry)) {
|
if (null == filter || filter.accept(entry)) {
|
||||||
@ -364,7 +367,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.channel.mkdir(dir);
|
getClient().mkdir(dir);
|
||||||
return true;
|
return true;
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
@ -375,7 +378,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
public boolean isDir(String dir) {
|
public boolean isDir(String dir) {
|
||||||
final SftpATTRS sftpATTRS;
|
final SftpATTRS sftpATTRS;
|
||||||
try {
|
try {
|
||||||
sftpATTRS = this.channel.stat(dir);
|
sftpATTRS = getClient().stat(dir);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
final String msg = e.getMessage();
|
final String msg = e.getMessage();
|
||||||
// issue#I4P9ED@Gitee
|
// issue#I4P9ED@Gitee
|
||||||
@ -403,7 +406,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
channel.cd(directory.replace('\\', '/'));
|
getClient().cd(directory.replace('\\', '/'));
|
||||||
return true;
|
return true;
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new FtpException(e);
|
throw new FtpException(e);
|
||||||
@ -418,7 +421,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
@Override
|
@Override
|
||||||
public boolean delFile(String filePath) {
|
public boolean delFile(String filePath) {
|
||||||
try {
|
try {
|
||||||
channel.rm(filePath);
|
getClient().rm(filePath);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -438,6 +441,8 @@ public class Sftp extends AbstractFtp {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ChannelSftp channel = getClient();
|
||||||
|
|
||||||
Vector<LsEntry> list;
|
Vector<LsEntry> list;
|
||||||
try {
|
try {
|
||||||
list = channel.ls(channel.pwd());
|
list = channel.ls(channel.pwd());
|
||||||
@ -562,7 +567,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public Sftp put(String srcFilePath, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
public Sftp put(String srcFilePath, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
||||||
try {
|
try {
|
||||||
channel.put(srcFilePath, destPath, monitor, mode.ordinal());
|
getClient().put(srcFilePath, destPath, monitor, mode.ordinal());
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -581,7 +586,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public Sftp put(InputStream srcStream, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
public Sftp put(InputStream srcStream, String destPath, SftpProgressMonitor monitor, Mode mode) {
|
||||||
try {
|
try {
|
||||||
channel.put(srcStream, destPath, monitor, mode.ordinal());
|
getClient().put(srcStream, destPath, monitor, mode.ordinal());
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -644,7 +649,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public Sftp get(String src, String dest) {
|
public Sftp get(String src, String dest) {
|
||||||
try {
|
try {
|
||||||
channel.get(src, dest);
|
getClient().get(src, dest);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -661,7 +666,7 @@ public class Sftp extends AbstractFtp {
|
|||||||
*/
|
*/
|
||||||
public Sftp get(String src, OutputStream out) {
|
public Sftp get(String src, OutputStream out) {
|
||||||
try {
|
try {
|
||||||
channel.get(src, out);
|
getClient().get(src, out);
|
||||||
} catch (SftpException e) {
|
} catch (SftpException e) {
|
||||||
throw new JschRuntimeException(e);
|
throw new JschRuntimeException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user