diff options
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/App.java | 45 | ||||
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/ftp/FtpImageUploader.java | 55 | ||||
-rw-r--r-- | src/main/java/org/openslx/satellitedaemon/ftp/GetFtpCredentials.java (renamed from src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java) | 3 |
3 files changed, 63 insertions, 40 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 6df6cff..6c88ece 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -1,25 +1,14 @@ package org.openslx.satellitedaemon; -import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; -import java.net.ConnectException; -import java.security.InvalidKeyException; -import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; -import java.security.SignatureException; -import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; - -import org.apache.commons.net.ftp.FTPSClient; import org.openslx.imagemaster.thrift.iface.FtpCredentials; -import org.openslx.satellitedaemon.util.GetFtpCredentials; +import org.openslx.satellitedaemon.ftp.FtpImageUploader; +import org.openslx.satellitedaemon.ftp.GetFtpCredentials; /** * Main class for uploading images from the HS-Server to the Satellite Server. @@ -27,36 +16,14 @@ import org.openslx.satellitedaemon.util.GetFtpCredentials; */ public class App { - public static void main( String[] args ) throws UnrecoverableKeyException, - NoSuchAlgorithmException, CertificateException, - FileNotFoundException, KeyStoreException, IOException, - InvalidKeyException, SignatureException + public static void main( String[] args ) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, FileNotFoundException, IOException { - String nilsIp = "132.230.4.23"; - int ftpPort = 2221; // TODO: A Thread that starts the call for new credentials and the upload // whenever a new image was sceduled in the db. FtpCredentials ftpc = GetFtpCredentials.now(); - FTPSClient ftpClient = new FTPSClient( "SSL", true ); - TrustManagerFactory trustManagerFactory = TrustManagerFactory - .getInstance( KeyManagerFactory.getDefaultAlgorithm() ); - KeyStore keystore = KeyStore.getInstance( "JKS" ); - keystore.load( new FileInputStream( new File( - "/home/michael/satellite-daemon/config/ftpsid.jks" ) ), - "password".toCharArray() ); - trustManagerFactory.init( keystore ); - TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; - ftpClient.setTrustManager( trustManager ); - try { - ftpClient.connect( nilsIp, ftpPort ); - if ( !ftpClient.login( ftpc.username, ftpc.password ) ) { - throw new ConnectException( "Could not login." ); - } - System.out.println( "Connected to " + nilsIp + ":" + ftpPort - + ". Reply code: " + ftpClient.getReplyCode() ); - } finally { - ftpClient.disconnect(); - } + FtpImageUploader ftpIU = new FtpImageUploader( ftpc ); + ftpIU.connectTest(); + } } diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpImageUploader.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpImageUploader.java new file mode 100644 index 0000000..db83646 --- /dev/null +++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpImageUploader.java @@ -0,0 +1,55 @@ +package org.openslx.satellitedaemon.ftp; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.ConnectException; +import java.net.SocketException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; + +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import org.apache.commons.net.ftp.FTPSClient; +import org.openslx.imagemaster.thrift.iface.FtpCredentials; + +public class FtpImageUploader +{ + static String nilsIp = "132.230.4.23"; + static int ftpPort = 2221; + FTPSClient ftpClient = new FTPSClient( "SSL", true ); + FtpCredentials ftpc = null; + + public FtpImageUploader(FtpCredentials ftpCredentials) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, FileNotFoundException, IOException { + TrustManagerFactory trustManagerFactory = TrustManagerFactory + .getInstance( KeyManagerFactory.getDefaultAlgorithm() ); + KeyStore keystore = KeyStore.getInstance( "JKS" ); + keystore.load( new FileInputStream( new File( + "/home/michael/satellite-daemon/config/ftpsid.jks" ) ), + "password".toCharArray() ); + trustManagerFactory.init( keystore ); + TrustManager trustManager = trustManagerFactory.getTrustManagers()[0]; + ftpClient.setTrustManager( trustManager ); + ftpc = ftpCredentials; + + } + + public void connectTest() throws SocketException, IOException { + try { + ftpClient.connect( nilsIp, ftpPort ); + if ( !ftpClient.login( ftpc.username, ftpc.password ) ) { + throw new ConnectException( "Could not login." ); + } + System.out.println( "Connected to " + nilsIp + ":" + ftpPort + + ". Reply code: " + ftpClient.getReplyCode() ); + } finally { + ftpClient.disconnect(); + } + } + +} diff --git a/src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java b/src/main/java/org/openslx/satellitedaemon/ftp/GetFtpCredentials.java index 27fea93..fff2f7f 100644 --- a/src/main/java/org/openslx/satellitedaemon/util/GetFtpCredentials.java +++ b/src/main/java/org/openslx/satellitedaemon/ftp/GetFtpCredentials.java @@ -1,4 +1,4 @@ -package org.openslx.satellitedaemon.util; +package org.openslx.satellitedaemon.ftp; import java.io.FileNotFoundException; import java.io.IOException; @@ -20,6 +20,7 @@ import org.openslx.imagemaster.thrift.iface.FtpCredentials; import org.openslx.imagemaster.thrift.iface.ImageData; import org.openslx.imagemaster.thrift.iface.ImageServer; import org.openslx.imagemaster.thrift.iface.ServerSessionData; +import org.openslx.satellitedaemon.util.EncryptWithServerIdPublicKey; public class GetFtpCredentials { |