Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Jsch and Secure File Transfer Protocol [SFTP]

user11979182Jan 19 2011 — edited Jan 20 2011
HI,

i used a small SFTP Client(java) to Connect to the SFTP Server and transfer a file. i can transfer the file successfully, but
how do confirm that the file content are secure.

Client : java SFTP Clinet using Jsch lib
Server : FTPShell Server


client program is
import com.jcraft.jsch.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
 
public class SftpClient {

    public static void main(String args[]) {

        JSch jsch = new JSch();
        Session session = null;

        try {
            session = jsch.getSession("user", "host",port);

            session.setConfig("StrictHostKeyChecking", "no");

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

            File file = new File("c:\\hello.txt");
            sftpChannel.put(new FileInputStream(file),"helloo.txt");
            sftpChannel.exit();
            session.disconnect();
        } catch (JSchException e) {
            e.printStackTrace();   
        } catch (SftpException e) 
        {
            e.printStackTrace();
        } catch(FileNotFoundException e)
        {
             e.printStackTrace();
        }
    }
}
thanks in advance

Edited by: sabre150 on 19-Jan-2011 02:07

Moderator action : added [ code] tags to improve readability.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2011
Added on Jan 19 2011
2 comments
1,961 views