cancel
Showing results for 
Search instead for 
Did you mean: 

SFTP from CPS

Former Member
0 Kudos

Hi,
We are running on M33 -61 .Is this version capable of sending files through SFTP .Has any one tried ? Any inputs would be greatly helpful.

Regrads

Balaji Natarajan

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

We created a redwood script using Java modules

Job parameters:

SFTP_hostnameStringInSFTP Hostname:Port
SFTP_usernameStringInSFTP username
SFTP_passwordStringIn
SFTP_localfilepathStringInLocal file Path
SFTP_remotefilepathStringInRemote File Path
JobIdStringIn
JobFileStringIn


import com.redwood.scheduler.api.model.Job;

import com.redwood.scheduler.api.model.JobFile;

import java.io.File;

import java.net.URLEncoder;

import org.apache.commons.vfs2.FileObject;

import org.apache.commons.vfs2.FileSystemException;

import org.apache.commons.vfs2.FileSystemOptions;

import org.apache.commons.vfs2.Selectors;

import org.apache.commons.vfs2.impl.StandardFileSystemManager;

import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;

import org.apache.commons.net.*;

import com.jcraft.jsch.*;

{

   // Setup SFTP Connection string parameter

   String hostName = SFTP_hostname;

   //String hostName = "10.0.0.162:22";

   String username = SFTP_username;

   String pws = SFTP_password;

   //String pws = "vjknfs8975h4wo";

   String password = URLEncoder.encode(pws);

   //String localFilePath = "C:/file/testfile.txt";

   String remoteFilePath = "/out/testfile.txt";     

   String remoteTempFilePath = "in/testTempFile.txt";

   Long j_jobid = jcsJob.getJobId();

   String j_filename = jf.getFileName();

   Long j_filesize = jf.getSize();

   String j_name = jf.getName();

   //String localFilePath = j_filename;

   String localFilePath = "/opt/redwood/platform/j2ee/cluster/server1/log/scheduler/lis/560000-569999/562479/System_562479_1.txt";

   jcsOut.println(j_jobid);

   jcsOut.println(j_filename);

jcsOut.println(j_filesize);

jcsOut.println(j_name);

   jcsOut.println("localFilePath = " + localFilePath);

  upload(hostName, usern

}


private String myjobFile(Long jobId, String jobFileName)

{

   String returnValue = "";

    Job j = jcsSession.getJobByJobId(jobId);

    JobFile jf = j.getJobFileByName(jobFileName);

   String fileName = jf.getFileName();

    Long fileSize = jf.getSize();

return returnValue;

}

public static void upload(String hostName, String username, String password, String localFilePath, String remoteFilePath)

{

   File file = new File(localFilePath);

   if (!file.exists())

            throw new RuntimeException("Error. Local file not found");

      StandardFileSystemManager manager = new StandardFileSystemManager();

   try {

            manager.init();

            // Create local file object

            FileObject localFile = manager.resolveFile(file.getAbsolutePath());

            // Create remote file object

            FileObject remoteFile = manager.resolveFile(createConnectionString(hostName, username, password, remoteFilePath), createDefaultOptions());

            /*

             * use createDefaultOptions() in place of fsOptions for all default

             * options - Ashok.

             */

            // Copy local file to sftp server

            remoteFile.copyFrom(localFile, Selectors.SELECT_SELF);

            System.out.println("File upload success");

            System.out.println(remoteFilePath);

        } catch (Exception e) {

            throw new RuntimeException(e);

        } finally {

            manager.close();

        }

}

public static String createConnectionString(String hostName, String username, String password, String remoteFilePath)

{

       return "sftp://" + username + ":" + password + "@" + hostName + "/" + remoteFilePath;

}

public static FileSystemOptions createDefaultOptions() throws FileSystemException

{

        // Create SFTP options

        FileSystemOptions opts = new FileSystemOptions();

        // SSH Key checking

        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");

        /*

* Using the following line will cause VFS to choose File System's Root

         * as VFS's root. If I wanted to use User's home as VFS's root then set

         * 2nd method parameter to "true"

         */

// Root directory set to user home

        SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false);

        // Timeout is count by Milliseconds

        SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000);

        return opts;

}

jcsOut.println("Test script");

jcsOut.println(fileName);

jcsOut.println(fileSize);   

Former Member
0 Kudos

Thanks for all your inputs .

@ Ooms ,

Are you using the above custom redwood script in CPS 8 for SFTP ?


Former Member
0 Kudos

Hi Balaji,

Yes we use V8 (M33.112) Full version.

Kr

Sjoerd

abhishek_singh29
Active Participant
0 Kudos

Hi,

I dont think sftp is supported by Redwood and jftp is supported. I would suggest and We are using different version of Redwood and we are using sftp with bash job def in redwood through unix.

Regards,

Abhishek

gmblom
Active Contributor
0 Kudos

Hello,

From BPA (Redwood version 9), the jftp client also supports sftp.

Regards Gerben

abhishek_singh29
Active Participant
0 Kudos

Hi Gerben,

Thanks, Please suggest how can we use it effectively. Currently, we are doing through UNIX (Bash) Script for file transfer from UNIX to Window server (global space).

But, we have a issues with it i.e. return code issues and the jobs is failing with 10001 return code error but file is getting transferred successfully. We had raised a support ticket but they are working on it, not much progress on that. As part of workaround, we are forcefully completing the job. We are using Redwood version 9.

Please suggest.

Regards,

Abhishek

gmblom
Active Contributor
0 Kudos

Hello,

The return code issue has to do with a recent change in version 9.0.14. All CMD scripts that issue a 'exit n' command will fail with a return code of 10001. This is because the exit command will stop the job and skip some of the post processing.

The way to do this as described in the bottom of all CMD scripts is to issue 'exit /b n' instead.

Regards Gerben

abhishek_singh29
Active Participant
0 Kudos

Thanks Gerben, yes..we current using the version 9.014.3. I will try it and let you know.

Many thanks for help.

Regards,

Abhishek

h_carpenter
Active Contributor
0 Kudos

Hi Balaji Natarajan,

Not using the native tools, but there are sftp clients that can be used with CPS.

What platform are we talking about ? I assume Windows, in which case you would want to look at PSFTP: PuTTY Download Page

Regards,

HP