Usage Note 61368: You can use the FILENAME PIPE access method as an alternative way of executing SFTP
You might encounter various issues that prevent you from executing SSH File Transfer Protocol (SFTP) within SAS® code using the FILENAME SFTP access method. Some of these issues are time-outs due to the file being moved or the file being too large, or the default SFTP messages being altered.
One alternative way to execute SFTP is to use the FILENAME PIPE access method. Here are some examples of using FILENAME PIPE to execute SFTP from SAS:
/* Example 1 */
/* Write out SFTP batchfile commands to a temp file. */
filename cmds temp;
data _null_;
put "cd /outdir"
/ "ls -lr *.zip"
/ "quit";
run;
/* Execute SFTP */
filename sftp pipe "sftp -o '-b %sysfunc(pathname(cmds))' ";
data _null_;
infile sftp;
file '<output file>';
put _infile_;
run;
/* Example 2 */
/* Build the sftp.txt file to hold SFTP batchfile commands. */
filename cmds "<any path>/sftp.txt" ;
data _null_;
file cmds ;
put 'cd /user/local/mydir' ;
put 'get remoteFile.txt localFile.txt' ;
run ;
/* FILENAME PIPE for SFTP command */
filename foo pipe "sftp -b $HOME/sftp.txt user@remotehost" ;
/* Execute the SFTP command by accessing the FILENAME PIPE. */
data _null_;
infile foo ;
input ;
run ;
/* Example 3 */
/* Build the sftp.txt file to hold SFTP batchfile commands. */
%let sftpcmds=D:\work\sftpcmd.txt;
%let host=host.com; /* Machine to connect with ftp */
%let userid=myuserid; /* ID to use with ftp command */
%let sftppwd=XXXX; /* Password for the ftp userid */
%let xfermode=binary; /* ASCII or binary mode xfer */
%let homedir=/testfolder; /* Directory to start in */
%let cmd=put; /* Using PUT to put files */
%let thefile1=test.csv; /* The file to PUT to (or GET from) */
%let localdir=D:\work;
filename sftpcmds "&sftpcmds";
data _null_;
file sftpcmds pad lrecl=80;
/* Using Windows Putty
filename test pipe "'C:\Program Files (x86)\PuTTY\PSFTP.EXE' -v -i F:\Putty_private_key.ppk -b F:\work\sasuser\sftp.txt remote@abc.com";
Operating System and Release Information
SAS System | Base SAS | Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows XP 64-bit Edition | 9.2 | | 9.2 TS1M0 | |
Microsoft® Windows® for x64 | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.2 | | 9.2 TS1M0 | |
Microsoft Windows XP Professional | 9.2 | | 9.2 TS1M0 | |
Windows Vista | 9.2 | | 9.2 TS1M0 | |
Windows Vista for x64 | 9.2 | | 9.2 TS1M0 | |
64-bit Enabled AIX | 9.2 | | 9.2 TS1M0 | |
64-bit Enabled HP-UX | 9.2 | | 9.2 TS1M0 | |
64-bit Enabled Solaris | 9.2 | | 9.2 TS1M0 | |
HP-UX IPF | 9.2 | | 9.2 TS1M0 | |
Linux | 9.2 | | 9.2 TS1M0 | |
Linux for x64 | 9.2 | | 9.2 TS1M0 | |
OpenVMS on HP Integrity | 9.2 | | 9.2 TS1M0 | |
Solaris for x64 | 9.2 | | 9.2 TS1M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
To execute SFTP, instead of using FILENAME SFTP, you can use FILENAME PIPE.
Date Modified: | 2018-01-01 11:40:53 |
Date Created: | 2017-11-07 13:15:27 |