on 07-27-2015 9:33 PM
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
We created a redwood script using Java modules
Job parameters:
SFTP_hostname | String | In | SFTP Hostname:Port |
SFTP_username | String | In | SFTP username |
SFTP_password | String | In | |
SFTP_localfilepath | String | In | Local file Path |
SFTP_remotefilepath | String | In | Remote File Path |
JobId | String | In | |
JobFile | String | In |
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.