Esiste un modo per implementare un FTP sicuro con org.apache.commons.net.ftp.FTPClient
?Secure FTP con org.apache.commons.net.ftp.FTPClient
In caso contrario, quali sono le altre opzioni per Java?
Esiste un modo per implementare un FTP sicuro con org.apache.commons.net.ftp.FTPClient
?Secure FTP con org.apache.commons.net.ftp.FTPClient
In caso contrario, quali sono le altre opzioni per Java?
È possibile utilizzare org.apache.commons.net.ftp. FTPSClient anziché org.apache.commons.net.ftp. FTPClient di avere ftp sicuro http://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPSClient.html
ne dite di provare Apache Camel,
Apache FTPClient non supporta SFTP al momento. Tuttavia, è possibile utilizzare JSch - Java Secure Channel.
Onkar Joshi entra in ulteriori dettagli della libreria da utilizzare per il trasferimento di file FTP, SFTP, FTPS in Java.
Un esempio di utilizzo JSch per trasferire i file con SFTP è la seguente:
...
private static final Logger logger = Logger.getLogger(YourClass.class.getName());
public boolean sendDataViaSFTP(String contents) throws Exception {
String hostname = "<FTP hostname/IP>";
String username = "<FTP username>";
String password = "<FTP password>";
String remoteDirectory = "<FTP remote directory>";
int ftpPort = 22;
logger.info("*** Creating FTP session. ***");
JSch jsch = new JSch();
Session session = null;
Channel channel = null;
ChannelSftp c = null;
//Now connect and SFTP to the SFTP Server
try {
//Create a session sending through our username and password
session = jsch.getSession(username, hostname, ftpPort);
logger.info("*** FTP Session created. ***");
session.setPassword(password);
//Security.addProvider(new com.sun.crypto.provider.SunJCE());
//Setup Strict HostKeyChecking to no so we dont get the
//unknown host key exception
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
logger.info("*** Session connected. ***");
//Open the SFTP channel
logger.info("*** Opening FTP Channel. ***");
channel = session.openChannel("sftp");
channel.connect();
c = (ChannelSftp) channel;
//Change to the remote directory
logger.info("*** Changing to FTP remote dir: " + remoteDirectory + " ***");
c.cd(remoteDirectory);
//Send the file we generated
try {
String filename = "myfile.txt";
logger.info("*** Storing file as remote filename: " + filename + " ***");
ByteArrayInputStream bis = new ByteArrayInputStream(contents.getBytes());
c.put(bis, filename);
return true;
} catch (Exception e) {
logger.info("*** Storing remote file failed. " + e.toString() + " ***");
throw e;
}
} catch (Exception e) {
logger.info("*** Unable to connect to FTP server. " + e.toString() + " ***");
throw e;
} finally {
//
//Disconnect from the FTP server
//
try {
if(session != null)
session.disconnect();
if(channel != null)
channel.disconnect();
if(c != null)
c.quit();
} catch (Exception exc) {
logger.severe("*** Unable to disconnect from FTP server. " + exc.toString()+" ***");
}
logger.info("*** SFTP Process Complete. ***");
}
}
...
In primo luogo, assicurarsi di aver compreso la differenza tra FTPS (FTP sicuro) e SFTP:
FTPS versus SFTP versus SCP
Se avete bisogno di FTPS (FTP sicuro), è possibile utilizzare FTPSClient
invece di FTPClient
da Apache Commons libreria:
https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPSClient.html
Se avete bisogno di SFTP, si veda:
01.233.
Java SFTP Transfer Library
Cosa hai trovato ancora? – Rob
C'è un motivo per cui non puoi SSH? Se no, prova Apache Mina o Jsch – amphibient
Che ne dici di cambiarlo in 'FTPSClient' che lo sottoclasse? –