Я пробовал библиотеки vfs2 и jsch, но в обеих из них возникла одна и та же проблема. Это пример кода, который я пробовал:
Код: Выделить всё
package com.example.ftp;
import com.jcraft.jsch.*;
import java.util.Vector;
public class Elmer1 {
public static void main(String[] args) {
String host = "aix";
String username = "user";
int port = 22;
String password = "pass"; // Replace with your password
String remoteDirectory = "/disk1/users/usr1"; // Replace with the remote folder path
JSch jsch = new JSch();
Session session = null;
try {
// Create the session object
session = jsch.getSession(username, host, port);
session.setPassword(password); // Set password
// Create properties for key exchange, ciphers, and host key algorithms
java.util.Properties config = new java.util.Properties();
session.setConfig(config);
// Disable strict host key checking for testing purposes (optional)
session.setConfig("StrictHostKeyChecking", "no");
// Connect to the session
session.connect();
// Open an SFTP channel
ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp");
channelSftp.connect();
// List files and directories in the remote directory
Vector list = channelSftp.ls(remoteDirectory);
System.out.println("Contents of " + remoteDirectory + ":");
for (ChannelSftp.LsEntry entry : list) {
if (entry.getAttrs().isDir()) {
// It's a directory
System.out.println("[DIR] " + entry.getFilename());
} else {
// It's a file
System.out.println("[FILE] " + entry.getFilename());
}
}
// Disconnect when done
channelSftp.disconnect();
session.disconnect();
} catch (JSchException | SftpException e) {
e.printStackTrace();
}
}
}
Код: Выделить всё
Contents of /disk1/users/usr1:
[DIR] .
[DIR] ..
[FILE] 99-4±±±±0A02-|PART±ASSEMBLY,±SAMPLE±IV-X.model
Подробнее здесь: https://stackoverflow.com/questions/791 ... -filenames
Мобильная версия