当前位置: 首页 > 知识库问答 >
问题:

如何用Java从FTPS服务器获取文件?

郜昊苍
2023-03-14

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

SSL/TLS

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

227进入被动模式

列表

NLST

需要521个PROT P

退出

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();
        }
    }
}

知道怎么了吗?

谢谢大家!

共有1个答案

芮意
2023-03-14

尝试在登录后执行此操作

  ftp.execPBSZ(0);
  ftp.execPROT("P");
 类似资料:
  • 我需要在Java中测试FTP/FTPS/SFTP/本地文件系统协议。 谢谢, 维贾伊·布尔雷

  • 我无法通过TLS/SSL(FTPS)服务器连接到FTP。我正在使用SimpleFTP库,通过我可以连接没有SSL的FTP服务器,但不能连接FTPS。 它在第2行(ftp.connect)给出了这个错误, SimpleFTP连接到FTP服务器时收到未知响应: 220---------欢迎使用Pure-FTPd[privsep][TLS]--------- 并且正在使用下面的代码

  • 我正在我的android应用程序中使用Apache Commons FTP库。 我正在使用带有JDK1.8的Android studio。 我很感激任何帮助,谢谢。

  • 我想用定制的发布

  • TDR:我需要在自己的后端拥有Google Cloud Functions。 我编写应用程序,它使用firebase(尤其是firestore)作为在nodejs上编写的我自己的后端和客户端应用程序之间的传输层。 有时,我需要从后端的客户端捕获一些事件,但我希望避免直接向后端执行http查询(因为我需要捕获脱机状态和其他问题)。最好在firestore文档中进行一些更改,在后端捕获这些更改并执行一

  • 我使用FileEntity httppost将文件发送到php apache服务器,但我不想更改该文件的名称。