简体   繁体   English

通过代理连接到FTPS

[英]Connect to FTPS through proxy

The initial problem we encountered was that a regular FTPs download started failing due to an untrusted server certificate. 我们遇到的最初问题是由于不受信任的服务器证书,常规FTP下载开始失败。 This prompted us to wonder whether the certificate had been updated without the counterparty notifying us so we wanted to download the current certificate and compare it to the one we have in our keystore. 这促使我们想知道证书是否已在没有对方通知我们的情况下进行了更新,因此我们想下载当前证书并将其与密钥库中的证书进行比较。

This seems to be a trickier problem than we had anticipated. 这似乎是一个比我们预期的棘手的问题。 The usual suspects (firefox, filezilla, ...) did not seem up to the task of connecting to an FTPs server through an FTP proxy so out of curiosity I started playing around with a more low level java approach. 通常的嫌疑人(firefox,filezilla等)似乎都没有通过FTP代理连接到FTPs服务器的任务,因此出于好奇,我开始尝试使用更底层的java方法。 I can not for the life of me get it to work though. 我无法为自己的一生而努力。

First (overly simplistic) java attempt: 第一次(过于简单)java尝试:

    // create proxy connection
    SocketFactory plainFactory = SocketFactory.getDefault();
    Socket proxy = plainFactory.createSocket(proxyServer, proxyPort);

    // create ssl connection on top of it?
    SSLSocketFactory sslFactory = getSocketFactory();
    SSLSocket socket = (SSLSocket) sslFactory.createSocket(proxy, server, port, true);

This approach obviously does not work. 这种方法显然行不通。

Next I started playing around with ftp4j (http://www.sauronsoftware.it/projects/ftp4j/) it seems to have a clean and accessible codebase: 接下来,我开始使用ftp4j(http://www.sauronsoftware.it/projects/ftp4j/),它似乎具有干净且可访问的代码库:

    FTPClient client = new FTPClient();
    client.setConnector(new FTPProxyConnector(proxyHost, proxyPort));
    client.getConnector().setConnectionTimeout(0);
    client.getConnector().setReadTimeout(0);
    client.setSSLSocketFactory(getSocketFactory());
    // also tried SECURITY_FTPS
    client.setSecurity(FTPClient.SECURITY_FTPES);
    client.connect(server, port);

This outputs: 输出:

REPLY: 220 Blue Coat FTP Service
SEND: USER anonymous
REPLY: 530-User Access denied.
REPLY: 530-
REPLY: 530-Usage: USER username@hostname
REPLY: 331        PASS userpassword
Exception in thread "main" java.io.IOException: Invalid proxy response

The proxy server has optional authentication and on our development servers we generally use "user@host" without proxy authentication. 代理服务器具有可选的身份验证,在我们的开发服务器上,我们通常使用“ user @ host”而不使用代理身份验证。 As such I assume the username, hostname and password are those of the remote server? 因此,我假设用户名,主机名和密码是远程服务器的用户名,主机名和密码?

So I tried adding the remote parameters, this does not work: 所以我尝试添加远程参数,这不起作用:

REPLY: 220 Blue Coat FTP Service
SEND: USER test@ftps.example.com
Exception in thread "main" java.io.IOException: FTPConnection closed

Adding the proxy user to match the bluecoat format does not seem to work either: 添加代理用户以匹配bluecoat格式似乎也不起作用:

USER %u@%h %s
PASS %p
ACCT %w

Any help with either of these two problems would be most welcome: 任何与这两个问题有关的帮助都将受到欢迎:

  • how to retrieve the server certificate from an ftps server through an ftp proxy 如何通过ftp代理从ftps服务器中检索服务器证书
  • how to connect to an ftps server through an ftp proxy in java 如何通过Java中的ftp代理连接到ftps服务器

You might want to try Apache Net commons libs. 您可能想尝试Apache Net Commons库。

Here is a similar thread that uses that Net Commons library 这是使用该Net Commons库的类似线程

Net commons also has a fully functional FTP Client Example so you can test with something you know works. 网络共享空间还具有功能齐全的FTP客户端示例,因此您可以使用已知的功能进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM