Sample 25211: Build and execute an ftp command file from within SASĀ®
Click on the Full Code tab for an example that
demonstrates how to use a SAS program to build an ftp command file that
issues PUT statements, then invokes the Unix ftp command via SAS.
Instead of prompting the user for the ftp commands, this example
obtains the ftp commands from the file.
You could modify this code to use the GET statement as well.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Note that before you use this code, you must substitute values
for ftpcmds=, host=, userid=, ftppwd=, and thefile=.
/* First, create macro variables to use in the ftp command. */
/* FTPCMDS is the actual file we will build with ftp commands. */
%let ftpcmds=/nfs/myhost/local/u//tmp/ftp.cmd;
%let host=machine; /* Machine to connect with ftp */
%let userid=user; /* ID to use with ftp command */
%let ftppwd=pw; /* Password for the ftp userid */
%let xfermode=binary; /* ASCII or binary mode xfer */
%let homedir=/home/; /* Directory to start in */
%let cmd=put; /* Using PUT to put files */
%let thefile=testftp.hp; /* The file to PUT to (or GET from) */
run;
/* Set up the fileref to execute the ftp command. */
filename ftpcmds "&ftpcmds";
data _null_;
file ftpcmds pad lrecl=80;
put "user &userid &ftppwd";
put "&xfermode";
put "cd &homedir";
put "&cmd &thefile";
run;
/* The control file for ftp has been built; now run it. */
filename doftp pipe "ftp -n &host < &ftpcmds";
data _null_;
infile doftp;
input;
put _infile_;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | SAS Reference ==> Statements ==> Data Access ==> FILENAME
|
Date Modified: | 2012-04-19 14:41:45 |
Date Created: | 2005-02-10 13:18:29 |
Operating System and Release Information
SAS System | Base SAS | 64-bit Enabled Solaris | n/a | n/a |
64-bit Enabled HP-UX | n/a | n/a |
ABI+ for Intel Architecture | n/a | n/a |
AIX | n/a | n/a |
HP-UX | n/a | n/a |
HP-UX IPF | n/a | n/a |
Linux | n/a | n/a |
Solaris | n/a | n/a |
Tru64 UNIX | n/a | n/a |
64-bit Enabled AIX | n/a | n/a |