cancel
Showing results for 
Search instead for 
Did you mean: 

How to read/write files from a SFTP server, using WebDynpro Java?

Former Member
0 Kudos

Hi All,

We have a requirement, where in, the business user could read /write PDF and excel files respectively to particular locations in the SFTP server.

I have gone through many links but am not getting any thing close to the requirement.

Challenges what I see:

1) It is a SFTP server and just not a FTP server.

2) It is a remote machine.

Solutions which I have thought of:

1) Using respository manager in KM to read/write data in remote server (SFTP server in our case)

2) Have got links like http://www.ajaxapp.com/2009/02/21/a-simple-java-ftp-connection-file-download-and-upload/ which talks about

how to write a Java program to connect to FTP.

Honestly, I have not tried this in my machine and so not sure how it will perform, that too on SFTP server.

So, request you all here, to let me know how to deal with this requirement, that will not make the application development complex.

Let me know if any body wants additional information or have questions.

Regards

DK

Accepted Solutions (0)

Answers (2)

Answers (2)

sugata_bagchi2
Active Contributor
0 Kudos

Hi DK,

You can use JSch API which is widely used for connecting a SFTP thru Java.

http://epaul.github.io/jsch-documentation/simple.javadoc/com/jcraft/jsch/package-summary.html

below is a sample code to connect and read file from an SFTP server -

import com.jcraft.jsch.*;

public class TestJSch {
   
public static void main(String args[]) {
       
JSch jsch = new JSch();
       
Session session = null;
       
try {
            session
= jsch.getSession("username", "127.0.0.1", 22);
            session
.setConfig("StrictHostKeyChecking", "no");
            session
.setPassword("password");
            session
.connect();

           
Channel channel = session.openChannel("sftp");
            channel
.connect();
           
ChannelSftp sftpChannel = (ChannelSftp) channel;
            sftpChannel
.get("remotefile.txt", "localfile.txt");
            sftpChannel
.exit();
            session
.disconnect();
       
} catch (JSchException e) {
            e
.printStackTrace(); 
       
} catch (SftpException e) {
            e
.printStackTrace();
       
}
   
}
}


http://www.jcraft.com/jsch/examples/

Former Member
0 Kudos

Hello All,

Looking forward to all of you for some related information to proceed with the requirement.

Regards

DK