class EsxiSshUtil {

    public static Session getSessionObject( String userName, String password, String hostName, int port,
                                            Properties sessionConfig )
    {

        Session session = null;

        // logger.debug("In getSessionObject");
        if ( userName != null && !"".equals( userName ) && password != null && hostName != null
            && !"".equals( hostName ) )
        {
            JSch jsch = new JSch();
            try
            {
                if ( sessionConfig != null
                    && InbandConstants.STRICT_HOST_KEY_CHECK_YES.equals( sessionConfig.getProperty( InbandConstants.STRICT_HOST_KEY_CHECKING ) ) )
                {
                    /*
                     * Getting location of .ssh/known_hosts to create session for only known hosts.
                     */
                    String fileLocation = InbandProperties.getKnownHostsLocation();
                    File f = new File( fileLocation );
                    if ( f.exists() && !f.isDirectory() )
                    {
                        jsch.setKnownHosts( fileLocation );
                    }
                    else
                    {
                        logger.debug( "The file: {} for getting .ssh/known_hosts doesn't exist", fileLocation );
                        throw new FileNotFoundException( "The file: " + fileLocation
                            + " for getting .ssh/known_hosts doesn't exist" );
                    }
                }

                session = jsch.getSession( userName, hostName, port );
                session.setPassword( password );

                if ( sessionConfig != null )
                {
                    session.setConfig( sessionConfig );
                }

                // logger.debug("COnfig set");
            }
            catch ( Exception e )
            {
                logger.error( "Creating SSH session failed", e );
            }
            return session;
        }
        // logger.debug("Before returning Session object");
        return null;
    }

}