summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/App.java
blob: 6df6cfff171061781dab5d3632beb606a13d6bc9 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                    

                               

                                     
                                 
                                         
                              




                                               
 




                                             
                                                           
                                                          

   
                                                                              

   


                                                                                  

                                                                              

                                                               
                                               
                                   
 













                                                                                              
                                                             

                                                                                 
                         



                                                                                        


                 
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;

/**
 * Main class for uploading images from the HS-Server to the Satellite Server.
 * 
 */
public class App
{
	public static void main( String[] args ) throws UnrecoverableKeyException,
			NoSuchAlgorithmException, CertificateException,
			FileNotFoundException, KeyStoreException, IOException,
			InvalidKeyException, SignatureException
	{
		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();
		}
	}
}