ftps 显示/隐式 客户端编程

ftps 上传文件,分为两种不同方式:
1.FTPS - 通过隐式的FTP.
2.FTPS - 通过显示的FTP.

下面是关于FTPS的描述,以及在两种上传方式间的编程转换:

FTPS/FTPES secured connection
The ftp4j library supports both FTPS (FTP over implicit TLS/SSL) and FTPES (FTP over explicit TLS/SSL).

The setSecurity() method can be used to turn on the feature:

client.setSecurity(FTPClient.SECURITY_FTPS); // enables FTPS
client.setSecurity(FTPClient.SECURITY_FTPES); // enables FTPES
Both methods must be called before connecting the remote server.

If the security is set to SECURITY_FTPS, the default port used by the connect() method changes to 990.

The client object, by default, negotiates SSL connections using the SSL socket factory provided by javax.net.ssl.SSLSocketFactory.getDefault(). The default socket factory can be changed calling the client setSSLSocketFactory() method. An alternative SSLSocketFactory, for example, can be used to trust every certificate given by the remote host (use it carefully):

import it.sauronsoftware.ftp4j.FTPClient;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

// ...

TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManager, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
FTPClient client = new FTPClient();
client.setSSLSocketFactory(sslSocketFactory);
client.setSecurity(FTPClient.SECURITY_FTPS); // or client.setSecurity(FTPClient.SECURITY_FTPES);

// ...

FTPClient.SECURITY_FTPS 通过隐式的FTP
FTPClient.SECURITY_FTPES 通过显示的FTP

具体的,更多更详细情况,请查阅下面的网址:
[url]http://www.sauronsoftware.it/projects/ftp4j/manual.php#6[/url]


验证方式:可使用开源工具Filezilla,进行验证。
工具Filezilla的下载:

[url]http://majg.iteye.com/blog/776224[/url]

你可能感兴趣的:(编程,Security,.net,Socket,PHP)