是否可以使用证书在不使用密码的情况下访问FileZilla FTPS服务器? 即使我使用FTPS服务器的密钥文件设置了trustmanager,也无法访问990端口。只能访问21端口。如何访问990端口?
我尝试了使用密码的无密码SFTP连接。并完成它。 但是FTPS不能正常运行。而且关于FTPS的信息太少了。
我尝试使用keyStore和TrustManager连接。但是无论是否使用keysotre和trustManager,我只能访问21个端口,并且还需要密码。private FTPSClient ftp = new FTPSClient();
private KeyStore loadStore(String storeType, File storePath, String storePass)
throws KeyStoreException, IOException, GeneralSecurityException {
KeyStore ks = KeyStore.getInstance(storeType);
FileInputStream stream = null;
try {
stream = new FileInputStream(storePath);
ks.load(stream, storePass.toCharArray());
} finally {
Util.closeQuietly(stream);
}
return ks;
}
public boolean connect() throws FTPException {
boolean result = false;
FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
{
// config.set
}
try {
System.out.println("FTPS connecting...");
//ftp.configure(config);
System.out.println(connectInfo.get(FTP.HOST)+", "+connectInfo.get(FTP.PORT));
//ftp.connect(connectInfo.get(FTP.HOST));
//我使用fileZilla FTPS服务器的certificate.crt制作了p12文件 // openssl pkcs12 -export -in vsftpd.crt -inkey vsftpd.key> vsftpd.p12 // keytool -importkeystore -srckeystore vsftpd.p12 -destkeystore keystore.jks -srcstoretype pkcs12 文件storeFile =新文件(“ C:\ Users \ Administrator \ Desktop \ MOCOMSYS \ ==== WORK ==== \ MI \ ETC \ tmp \ vsftpd.p12“);
KeyStore keyStore=null;
X509TrustManager defaultTrustManager=null;
try {
keyStore = loadStore("JKS", storeFile, "mocomsys1");
defaultTrustManager = TrustManagerUtils.getDefaultTrustManager(keyStore);
} catch (KeyStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//whatever i use trustmanager or not, i can access 21port.
//ftp.setTrustManager(defaultTrustManager);
ftp.connect(connectInfo.get(FTP.HOST), Integer.parseInt(connectInfo.get(FTP.PORT)));
System.out.println(FTPReply.isPositiveCompletion(ftp.getReplyCode()));
ftp.setSoLinger(true, 1000);
ftp.setSoTimeout(Integer.parseInt(connectInfo.get(FTP.TIMEOUT)));
System.out.println("~~~~~~~~~~~~~~~~~~");
System.out.println(ftp.getAuthValue());
System.out.println(ftp.getLocalPort());
System.out.println(ftp.getPassivePort());
System.out.println(ftp.getRemotePort());
System.out.println(ftp.getSystemName());
System.out.println(ftp.getSystemType());
System.out.println(ftp.getRemoteAddress());
result = ftp.login(connectInfo.get(FTP.USERNAME), connectInfo.get(FTP.PASSWORD));
ftp.execPBSZ(0);
ftp.execPROT("P");
ftp.enterLocalPassiveMode();
System.out.println("FTPS connection : "+result);
// FileEntryParser
} catch (NumberFormatException e) {
throw new FTPException(e);
} catch (SocketException e) {
throw new FTPException(e);
} catch (IOException e) {
throw new FTPException(e);
}
return result;
}
如果我使用990端口,则应连接良好。但是这个代码不是。 服务器和Java说“连接已关闭,没有任何指示。”