i have an issue transferring files to Windows FTP server from Unix/Mac/Linux env.
while the exact same java code works from windows pc. from *Nix/Mac the transfer only worked with this commands on the ftp session
set ftps:initial-prot
set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate no
while on my windows machine i didnt need them - i assume it relates to system variable.
This is my java code
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();
}
What is equivalent of this parameters in the FTPS Apache class ?
set ftps:initial-prot
set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate no
It appears that Windows NT does not support writing data in FTP.BLOCK_TRANSFER_MODE
Easy fix is
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.