Archive for April, 2008

Technologies we Used for the election commission of Nepal

Saturday, April 12th, 2008

Ok here is the list of technologies that we used for the election commission

  • Database DB2 [gifted to Election commission of Nepal from IBM]
  • Desktop program in Visual Basic 6 with extensive use of VSFlex grid
  • Desktop Reporting and Book printing in Crystal Reports 6
  • PHP web application
  • extensive use of xml and ajax(javascript) for playing with the offline database
  • using actionscript 2 and flash 8 for generating the charts
  • Using java, Apache net tools and J2ssh for perodic updates of the files in the ftp server
  • Using Ext2 js for interactive web page[a little]  

Storing the directory structure in a zip file(java)

Saturday, April 12th, 2008

simple
just add the zipentry files containng the file path
like
ZipEntry e=new ZipEntry(”abc/a.txt”);
ZipEntry e2=new ZipEntry(”efg/a.txt”);

will keep 2 folders abc and efg with two files

SSH login+SFTP using java and execute command

Saturday, April 12th, 2008

Dear All
I needed to automate the login to a ssh client and execute some commands after hours of googling and trying couples of API and free tools i conclude that the best tool for me is j2ssh is
http://sourceforge.net/projects/sshtools

Here is snapshot of how you can login and fire some commands

ConfigurationLoader.initialize(false);

SshClient ssh = new SshClient();

ssh.setSocketTimeout(30000);

SshConnectionProperties properties = new SshConnectionProperties();

properties.setHost(this.server);

properties.setPrefPublicKey(”ssh-rsa”);

// Connect to the host

ssh.connect(properties);

// Create a password authentication instance

PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();

// Get the users name

pwd.setUsername(this.user); // Get the password

pwd.setPassword(this.password);

// Try the authentication

int result = ssh.authenticate(pwd);

// Evaluate the result

this.field.setText(”firing command”);

SessionChannelClient session = ssh.openSessionChannel();

session.requestPseudoTerminal(”vt100″, 80, 24, 0, 0, “”);

if (session.startShell()) {

ByteArrayInputStream ins1 = new ByteArrayInputStream(”cd reports;cd CAResults;unzip -o ToUpload.zip\r”.getBytes());

//ByteArrayInputStream ins2=new ByteArrayInputStream(”cd reports\r”.getBytes());

// ByteArrayInputStream ins3=new ByteArrayInputStream(”cd reports\r”.getBytes());

IOStreamConnector input = new IOStreamConnector();

IOStreamConnector output = new IOStreamConnector();

IOStreamConnector error = new IOStreamConnector();

output.setCloseOutput(false);

input.setCloseInput(false);

error.setCloseOutput(false);

input.connect(ins1, session.getOutputStream());

output.connect(session.getInputStream(), System.out);

error.connect(session.getStderrInputStream(), System.out);

// session.getState().waitForState(ChannelState.CHANNEL_CLOSED);

Thread.sleep(30000);

this.field.setText(”Over and out from USA”);

session.close();

Here is how you can do SFTP

ConfigurationLoader.initialize(false);

this.clientS = new SshClient();

clientS.connect(this.server);

PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();

pwd.setUsername(this.user);

pwd.setPassword(this.password);

int result = clientS.authenticate(pwd);

this.client = clientS.openSftpClient();

this.client.cd(this.workingdir);

this.field.setText(this.client.pwd());

this.client.put(local.toString());

Happy new year

Thursday, April 10th, 2008

Happy new year Card to all my frens and my moti

My desktop from Election commission of nepal

Thursday, April 10th, 2008

Here is screen print from my desktop from election system

Web reportsJAVa Application for ftp upload