Thursday, 12 December 2013

Java SFTP Connection and File Transfer using JSch

Requirement to change the location of a file via SFTP  using  JCraft
       

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;


public class Send {
 

    public static  void main (String args[] ) {
        String SFTPHOST = "";
        int SFTPPORT = 22;
        String SFTPUSER = "";
        String SFTPPASS = "";
        Session session = null;
        Channel channel = null;
        ChannelSftp channelSftp = null;
        System.out.println("preparing the host information for sftp.");

        try {
            JSch jsch = new JSch();
            session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
            session.setPassword(SFTPPASS);
            java.util.Properties config = new java.util.Properties();
            config.put("StrictHostKeyChecking", "no");
            session.setConfig(config);
            session.connect();
            System.out.println("Host connected.");
            channel = session.openChannel("sftp");
            channel.connect();
            System.out.println("sftp channel opened and connected.");
            channelSftp = (ChannelSftp) channel;
            channelSftp.cd("/export/home/sanal.s");
            System.out.println(channelSftp.getHome() );
            File f = new File("c:\\party1.xml");
            channelSftp.put(new FileInputStream(f), f.getName());
            channelSftp.rename("/export/home/sanal.s/party1.xml", "/export/home/sanal.s/test/party1.xml");
            System.out.println("File transfered successfully to host.");

        } catch (Exception ex) {
             System.out.println("Exception found while tranfer the response.");
        }
        finally{
            channelSftp.exit();
            System.out.println("sftp Channel exited.");
            channel.disconnect();
            System.out.println("Channel disconnected.");
            session.disconnect();
            System.out.println("Host Session disconnected.");
        }
    }  
}

       
 

Saturday, 31 August 2013

Jquery to change dropdown value of 2nd dropdown on chnage of first.

So this is a very simple code.
Essentially we can use this logic for other html elements as well. Since I encountered such a situation. Posting this for the dropdown element.
   wmdropdown_countrycode:- id of dropdown 1
    wmdropdown_nationality:- id of dropdown 2

myfunction
() {
$(
'#wmdropdown_countrycode').change(function(){ var selectedCountry = $(this).attr('value');
$(
'#wmdropdown_nationality').find('option').each(function() { if($(this).val().toLowerCase() == selectedCountry.toLowerCase()){
$(
this).attr('selected','selected');
}
});
});
}


Sunday, 24 March 2013

Jquery Implementation for Date field, Expander and search highlighting field

Using the Jquery Expander plugin for a read more ... read less implentation to your site / project.

The source files required JS,CSS,IMAGE  Files you require for the implementation:-

 <link href="css/ui-lightness/jquery-ui-1.9.2.custom.css" rel="stylesheet" />
   <script src="js/jquery-1.8.3.js"></script>
   <script src="js/jquery-ui-1.9.2.custom.js"></script>
    <script src="js/jquery_expander.js"></script>

In your document. ready function to need to call the datepicker function for the html element in your page
creationDate is the id of the html element.

   $("#creationDate").datepicker({dateFormat: $.datepicker.ATOM,buttonImage: 'img/calendar.png', buttonText:'', buttonImageOnly: true, constrainInput: true, showButtonPanel: false, showOn: 'button'});


Using the jquery highlight,expander plugin  will highlight your search text :

Call in your document ready function
  var keywordText=document.getElementById("keywordText").value;
      $('div.expandable p').highlight(keywordText);
      $('div.expandable p').expander(); 


 In your page the div to be expanded and text to be highlighted

<div class="expandable"><p><c:out value='${instance.col3}' escapeXml='true'/></p></div>






AWS Certificate Manager - Import Certificate

How to import a certificate. Use Key Store Explorer to open the cert and export keypair in PEM format  This will save a file cert.pem. Make ...