DATA Step, Macro, Functions and more

How to SFTP Between Two SAS Environments?

Accepted Solution Solved
Reply
Contributor
Posts: 73
Accepted Solution

How to SFTP Between Two SAS Environments?

Hi All,

 

I have a SAS Dataset in one of my SAS Environment which I move it to another environment using SFTP in SAS Code.

I could do this by logging in to Linux box and then move it manually, but for a project I have to move this multiple times. Could you please assist me with sample code using which I could do the same?

 

Both environments are on LINUX Hosts.

 

Thanks


Accepted Solutions
Solution
‎11-24-2016 05:25 AM
Super User
Posts: 6,930

Re: How to SFTP Between Two SAS Environments?

My preferred method of using the commandline is this:

filename oscmd pipe "sftp sourcefile targetfile 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;

The 2>&1 redirects stderr (standard error output) to stdout, so you get any error messages into your infile. The data _null_ then executes the command and writes output to the SAS log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,930

Re: How to SFTP Between Two SAS Environments?

Set up public/private key authentication between the users on both hosts. Then you can use sftp from the commandline without the need to log on.

To use this from SAS code, you will need to have xcmd enabled, of course.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 73

Re: How to SFTP Between Two SAS Environments?

It's working fine with commandline, Could you please direct me to a sample code that I can use to do it from sas code(EG)?

 

thanks

Solution
‎11-24-2016 05:25 AM
Super User
Posts: 6,930

Re: How to SFTP Between Two SAS Environments?

My preferred method of using the commandline is this:

filename oscmd pipe "sftp sourcefile targetfile 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;

The 2>&1 redirects stderr (standard error output) to stdout, so you get any error messages into your infile. The data _null_ then executes the command and writes output to the SAS log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 73

Re: How to SFTP Between Two SAS Environments?

Thanks, this resolved the issue.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 202 views
  • 0 likes
  • 2 in conversation