java - 如何使用java从FTPS服务器获取文件?

标签 java ftp ftps ftp-server

我正在尝试访问我在 ftps 服务器中创建的路径中的文件夹,但它没有返回任何内容,它正在连接但不返回任何内容,如果我将服务器配置更改为仅 ftp 它可以工作。我正在使用 FileZilla Server,其配置如上。

SSL/TLS

在 SSL/TLS 设置中标记 true 启用 FTP over SSL/TLS 支持 (FTPS) 并允许显式 FTP over TLS

我的用户配置是:

在 FireZilla 服务器的一般用户配置中,“Force SSL for user login”是正确的。

服务器关于连接的日志正在收到一条消息,我不知道它是否有帮助:

227进入被动模式

列表

需要 521 PROT P

PASV

227进入被动模式

NLST

需要 521 PROT P

退出

我要连接的示例类在上面具有所有权限:

公共(public)类 FTPClientExample2 {

public static void main(String[] args)
{
    String server = "myip";
    int port = 2121;
    String user = "joao";
    String pass = "1234";

    boolean error = false;
    FTPSClient ftp = null;
    try
    {
        ftp = new FTPSClient("SSL");
        ftp.setAuthValue("SSL");
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        int reply;

        ftp.connect(server, port);
        System.out.println("Connected to ftp.wpmikz.com.cn");
        System.out.print(ftp.getReplyString());

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply))
        {
            ftp.disconnect();
            System.err.println("FTP server refused connection.");
            System.exit(1);
        }
        ftp.login(user, pass);
        // ... // transfer files
        ftp.setBufferSize(1000);
        ftp.enterLocalPassiveMode();
        // ftp.setControlEncoding("GB2312");
        ftp.changeWorkingDirectory("/");
        ftp.changeWorkingDirectory("/ae"); //path where my files are
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        System.out.println("Remote system is " + ftp.getSystemName());

        String[] tmp = ftp.listNames();  //returns null
        System.out.println(tmp.length);
    }
    catch (IOException ex)
    {
        System.out.println("Oops! Something wrong happened");
        ex.printStackTrace();
    }
    finally
    {
        // logs out and disconnects from server
        try
        {
            if (ftp.isConnected())
            {
                ftp.logout();
                ftp.disconnect();
            }
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }
}

知道哪里出了问题吗?

谢谢大家!

最佳答案

登录后尝试执行此操作

  ftp.execPBSZ(0);
  ftp.execPROT("P");

关于java - 如何使用java从FTPS服务器获取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29475780/

相关文章:

java - MongoDB : JSON util is deprecated

java - 通过 for 循环循环的通用集合

c# - 使用 C#.Net 通过 FTPS (SSL/TLS) 传输文件

ssl - 使用客户端身份验证证书设置 FTPS 连接

java - JDK 8u161 中 Apache FTPS 客户端中的 SSL session 重用

java - 仅声明类类型变量时的内存分配

java - 使用jSTL向jsp传递一组参数包括

ios - NSURLRequest 目录列表解析

c# - 如何在 C# 中使用 FtpWebRequest 设置端口号?

python - 检查由 Twisted 的 FTPClient.retrieveFile 方法检索的文件的完整性