apache FTPS with proxy get timeout when transferring file

152 views Asked by At

I am trying to use an ftps client with proxy. I am using this library by apache: org.apache.commons.net.ftp;

The problem is, that it looks like when I set proxy to the ftps client, it is connecting and also doing login, but gets connect timed out when trying to transfer the file.

though if I don't set proxy on the ftps client, the file is being written succesfully.

just to mention, if I use normal FTP client (with proxy, i.e. new FTPClient()), and not FTPS client (i.e. new FTPSClient()), it also works.

This is how I create the ftps client:

FTPClient ftpClient = new FTPSClient();
ftpClient.setConnectTimeout(timeout);
ftpClient.setCopyStreamListener(new FileCopyListener(context, "Transfer file using ftp."));

// setting the proxy:
ftpClient.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(OUTBOUND_HTTP_PROXY_HOST, OUTBOUND_HTTP_PROXY_PORT)));
ftpClient.setRemoteVerificationEnabled(false);

// connecting:
ftpClient.connect(host, port);
// login
ftpClient.login(username, password)

// some file configuration
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
ftpClient.setBufferSize(DataSourceProperties.BUFFER_SIZE);

// has encryption
((FTPSClient) ftpClient).execPBSZ(0);
((FTPSClient) ftpClient).execPROT("P");

// now trying to transfer file
for (File file : files) {
    try (InputStream fileInputStream = new FileInputStream(file)) {
        String remoteFileName = file.getName();
        if (ftpClient.storeFile(remoteFileName, fileInputStream)) { // *** THIS IS WHERE I GET THE TIMEOUT
           logger.info("File uploaded successfully");
        } else {
            throw new Exception(errorMessage);
        }
        traceLogger.info(LogFactory.createLog(stepId, "Complete uploading file", parameters));
    }
}

any idea?

0

There are 0 answers