Apache FTPS 客户端 storeFile 从 Unix/Linux/Max 问题到 windows FTPS 服务器

Apache FTPS Client storeFile to windows FTPS server from Unix/Linux/Max issue

我在将文件从 Unix/Mac/Linux 环境传输到 Windows FTP 服务器时遇到问题。

而完全相同的 java 代码适用于 windows 电脑。 来自 *Nix/Mac 的传输仅适用于 ftp 会话

上的此命令
set ftps:initial-prot 
set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate no

在我的 windows 机器上我不需要它们 - 我认为它与系统变量有关。

这是我的java代码

protected FTPClient getClient(DeliveryDetails details) {
    return new FTPSClient(false); // the connection is Explicit
}

public void setClient(FTPClient client, DeliveryDetails details) throws Exception {
    client.setConnectTimeout(10000);
    client.setDefaultTimeout(1000 * 60 * 2);
    client.setControlKeepAliveTimeout(300);
    client.setDataTimeout(15000);
    client.connect(ftpDetails.host, ftpDetails.port);
    client.setBufferSize(1024 * 1024);
    client.login(ftpDetails.username, ftpDetails.getSensitiveData());
    client.setControlEncoding("UTF-8");
    client.setFileType(FTP.BINARY_FILE_TYPE);
    client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
    FTPSClient ftpsClient = (FTPSClient) client;
    ftpsClient.execPBSZ(0);
    ftpsClient.execPROT("P");
    // both with it and without it didnt work ftpsClient.setWantClientAuth(false);
}

public void saveToServer(FTPClient client, File fileName, InputStream stream){
    BufferedInputStream bis = new BufferedInputStream(stream);
    boolean isSaved = client.storeFile(filename, bis);
    client.logout();
}

‌在 FTPS Apache class 中这个参数等效于什么?

set ftps:initial-prot 
set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate no

看来Windows NT不支持在FTP.BLOCK_TRANSFER_MODE

中写入数据

简单的解决方法是

    private static final String WINDOWS_NT_SYTEM_TYPE = "Windows_NT";
   ....
   ....
    try {
            String res = client.getSystemType();
            if (res.equals(WINDOWS_NT_SYTEM_TYPE)) {
                client.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
            } else {
                client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
            }
        }