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
具体的,更多更详细情况,请查阅下面的网址:
http://www.sauronsoftware.it/projects/ftp4j/manual.php#6
验证方式:可使用开源工具Filezilla,进行验证。
工具Filezilla的下载:
http://majg.iteye.com/blog/776224
分享到:
相关推荐
.NET 隐式FTPS源代码是一个用于在.NET 2.0及更高版本环境中实现FTP安全传输协议(FTPS)的编程示例。FTPS,也称为FTP-SSL或FTP over TLS/SSL,是一种增强版的FTP协议,通过在FTP会话中添加SSL/TLS加密层来提供数据的...
隐式调用”主要涉及隐式FTPS。 隐式FTPS在连接建立之初就要求使用SSL/TLS加密,端口通常为990,而不是标准FTP的21端口。在隐式模式下,客户端首先通过安全连接请求服务,然后进行FTP命令交换。这样可以确保整个会话...
FTPS分为两种模式: Explicit(明示式)和Implicit(隐式)模式。在 Explicit 模式下,客户端先建立一个未加密的FTP连接,然后请求服务器切换到SSL/TLS模式。在 Implicit 模式下,客户端在连接时立即请求安全连接。...
总的来说,Java通过ftp4j库实现实现FTPS加密上传,涉及网络通信、安全协议、文件操作等多个方面,需要综合运用编程技能和网络知识。在具体实践中,要确保代码的健壮性和安全性,同时考虑性能和用户体验。
在Java编程中,SSLSocket是用于实现安全套接字层(SSL)或传输层安全(TLS)协议的类,这些协议提供了网络通信的安全性,包括数据加密、服务器身份验证和消息完整性。当我们需要在Java应用程序中使用FTP(文件传输...
- 显式FTPS:在标准FTP会话建立后,客户端请求启动SSL/TLS安全会话。服务器响应并开始加密连接。 - 隐式FTPS:从连接开始就使用SSL/TLS,使用的是一个特殊的端口(通常是990),而不是标准FTP的21端口。 在C#中使用...
WinSCP是一个功能强大的开源SFTP、FTP、FTPS客户端,它提供了命令行接口(CLI)以及.NET库,方便在代码中集成FTP功能。 标题中的"调用Winscp.com 连接FTP"意味着我们将使用WinSCP的命令行版本(winscp.com)来执行...