mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix code and add Ftp
This commit is contained in:
@@ -28,7 +28,7 @@ public class FtpTest {
|
||||
@Disabled
|
||||
public void ftpsTest() {
|
||||
final FTPSClient ftpsClient = new FTPSClient();
|
||||
final Ftp ftp = new Ftp(ftpsClient);
|
||||
final CommonsFtp ftp = new CommonsFtp(ftpsClient);
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
@@ -39,7 +39,7 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void cdTest() {
|
||||
final Ftp ftp = new Ftp("looly.centos");
|
||||
final CommonsFtp ftp = CommonsFtp.of("looly.centos");
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
@@ -50,7 +50,7 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void uploadTest() {
|
||||
final Ftp ftp = new Ftp("localhost");
|
||||
final CommonsFtp ftp = CommonsFtp.of("localhost");
|
||||
|
||||
final boolean upload = ftp.uploadFile("/temp", FileUtil.file("d:/test/test.zip"));
|
||||
Console.log(upload);
|
||||
@@ -61,17 +61,17 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void reconnectIfTimeoutTest() throws InterruptedException {
|
||||
final Ftp ftp = new Ftp("looly.centos");
|
||||
final CommonsFtp ftp = CommonsFtp.of("looly.centos");
|
||||
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
|
||||
Console.log("休眠一段时间,然后再次发送pwd命令,抛出异常表明连接超时");
|
||||
Thread.sleep(35 * 1000);
|
||||
|
||||
try{
|
||||
try {
|
||||
Console.log("打印pwd: " + ftp.pwd());
|
||||
}catch (final FtpException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final FtpException e) {
|
||||
Console.error(e, e.getMessage());
|
||||
}
|
||||
|
||||
Console.log("判断是否超时并重连...");
|
||||
@@ -85,8 +85,8 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void recursiveDownloadFolder() {
|
||||
final Ftp ftp = new Ftp("looly.centos");
|
||||
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
|
||||
final CommonsFtp ftp = CommonsFtp.of("looly.centos");
|
||||
ftp.recursiveDownloadFolder("/", FileUtil.file("d:/test/download"));
|
||||
|
||||
IoUtil.closeQuietly(ftp);
|
||||
}
|
||||
@@ -94,11 +94,11 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void recursiveDownloadFolderSftp() {
|
||||
final JschSftp ftp = new JschSftp("127.0.0.1", 22, "test", "test");
|
||||
final JschSftp ftp = JschSftp.of("127.0.0.1", 22, "test", "test");
|
||||
|
||||
ftp.cd("/file/aaa");
|
||||
Console.log(ftp.pwd());
|
||||
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
|
||||
ftp.recursiveDownloadFolder("/", FileUtil.file("d:/test/download"));
|
||||
|
||||
IoUtil.closeQuietly(ftp);
|
||||
}
|
||||
@@ -106,13 +106,13 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void downloadTest() {
|
||||
final Ftp ftp = new Ftp("localhost");
|
||||
final CommonsFtp ftp = CommonsFtp.of("localhost");
|
||||
|
||||
final List<String> fileNames = ftp.ls("temp/");
|
||||
for(final String name: fileNames) {
|
||||
for (final String name : fileNames) {
|
||||
ftp.download("",
|
||||
name,
|
||||
FileUtil.file("d:/test/download/" + name));
|
||||
name,
|
||||
FileUtil.file("d:/test/download/" + name));
|
||||
}
|
||||
|
||||
IoUtil.closeQuietly(ftp);
|
||||
@@ -121,7 +121,7 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void isDirTest() throws Exception {
|
||||
try (final Ftp ftp = new Ftp("127.0.0.1", 21)) {
|
||||
try (final CommonsFtp ftp = CommonsFtp.of("127.0.0.1", 21)) {
|
||||
Console.log(ftp.pwd());
|
||||
ftp.isDir("/test");
|
||||
Console.log(ftp.pwd());
|
||||
@@ -131,7 +131,7 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void existSftpTest() {
|
||||
try (final JschSftp ftp = new JschSftp("127.0.0.1", 22, "test", "test")) {
|
||||
try (final JschSftp ftp = JschSftp.of("127.0.0.1", 22, "test", "test")) {
|
||||
Console.log(ftp.pwd());
|
||||
Console.log(ftp.exist(null));
|
||||
Console.log(ftp.exist(""));
|
||||
@@ -154,7 +154,7 @@ public class FtpTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void existFtpTest() throws Exception {
|
||||
try (final Ftp ftp = new Ftp("127.0.0.1", 21)) {
|
||||
try (final CommonsFtp ftp = CommonsFtp.of("127.0.0.1", 21)) {
|
||||
Console.log(ftp.pwd());
|
||||
Console.log(ftp.exist(null));
|
||||
Console.log(ftp.exist(""));
|
||||
|
||||
@@ -35,7 +35,7 @@ public class JschTest {
|
||||
@Disabled
|
||||
public void bindPortTest() {
|
||||
//新建会话,此会话用于ssh连接到跳板机(堡垒机),此处为10.1.1.1:22
|
||||
final JschSession session = new JschSession(new Connector("looly.centos", 22, "test", "123456"));
|
||||
final JschSession session = new JschSession(Connector.of("looly.centos", 22, "test", "123456"));
|
||||
// 将堡垒机保护的内网8080端口映射到localhost,我们就可以通过访问http://localhost:8080/访问内网服务了
|
||||
session.bindLocalPort(8080, new InetSocketAddress("172.20.12.123", 8080));
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class JschTest {
|
||||
@Disabled
|
||||
public void bindRemotePort() {
|
||||
// 建立会话
|
||||
final JschSession session = new JschSession(new Connector("looly.centos", 22, "test", "123456"));
|
||||
final JschSession session = new JschSession(Connector.of("looly.centos", 22, "test", "123456"));
|
||||
// 绑定ssh服务端8089端口到本机的8000端口上
|
||||
session.bindRemotePort(new InetSocketAddress(8089), new InetSocketAddress("localhost", 8000));
|
||||
// 保证一直运行
|
||||
@@ -55,7 +55,7 @@ public class JschTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void sftpTest() {
|
||||
final JschSession session = new JschSession(new Connector("looly.centos", 22, "root", "123456"));
|
||||
final JschSession session = new JschSession(Connector.of("looly.centos", 22, "root", "123456"));
|
||||
final JschSftp jschSftp = session.openSftp(CharsetUtil.UTF_8);
|
||||
jschSftp.mkDirs("/opt/test/aaa/bbb");
|
||||
Console.log("OK");
|
||||
@@ -65,7 +65,7 @@ public class JschTest {
|
||||
@Test
|
||||
@Disabled
|
||||
public void reconnectIfTimeoutTest() throws InterruptedException {
|
||||
final JschSession session = new JschSession(new Connector("sunnyserver", 22,"mysftp","liuyang1234"));
|
||||
final JschSession session = new JschSession(Connector.of("sunnyserver", 22,"mysftp","liuyang1234"));
|
||||
final JschSftp jschSftp = session.openSftp(CharsetUtil.UTF_8);
|
||||
|
||||
Console.log("打印pwd: " + jschSftp.pwd());
|
||||
|
||||
@@ -34,7 +34,7 @@ public class SftpTest {
|
||||
@BeforeEach
|
||||
@Disabled
|
||||
public void init() {
|
||||
sshjSftp = new SshjSftp("ip", 22, "test", "test", CharsetUtil.UTF_8);
|
||||
sshjSftp = SshjSftp.of("ip", 22, "test", "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user