Sample 36065: Using SAS® software to access multiple files on an FTP server
The two samples included on the Full Code tab use the MGET FTP option to access multiple files on an FTP server. The first sample shows you how to process the data in the files into a SAS DATA step. The second sample illustrates how to move files from an FTP server to your local system.
For more information about FTP options and the MGET option, see FILENAME Statement, FTP Access Method in the SAS® 9.2 Language Reference: Dictionary, Third Edition.
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.
Ensure that you set valid values in the statements denoted with /* */ comment delimiters.
This code cannot be run as stand-alone code because you need an FTP server connection to run the code.
/* SAMPLE 1: Reading files from FTP server and processing with datastep */
filename IN ftp ('saskcw.flat.file' 'saskcw.flat.file1') host="mvshost.company.com"
user='userid'
pass='password' debug mget;
/*or using wildcards.... */
FILENAME IN FTP '*.sas' HOST='host.company.com
user='userid'
pass='password' mget debug;
data stuff;
infile in;
input;
x=_infile_;
run;
/* SAMPLE 2: Moving files from FTP server to local system using OS FTP */
%let ftpcmds=ftp.cmds;
%let host=host.company.com; /* specify machine to connect with ftp */
%let userid=userid; /* specify id to use with ftp command */
%let ftppwd=password; /* specify pwd for the ftp userid */
%let xfermode=ascii; /* specify ascii or binary mode xfer */
%let homedir=./; /* optional: specify directory on ftp server */
%let localdir=\public; /* optional: specify local directory */
run;
/* Setup libref to execute the ftp command */
filename ftpcmds "&ftpcmds";
data _null_;
file ftpcmds pad lrecl=80;
put "user &userid &ftppwd";
put "verbose";
put "trace";
put "&xfermode";
put "cd &homedir";
put "lcd &localdir";
put "prompt"; /* used for MPUT and MGET commands */
put "mget *.sas"; /* specify wilcard used for MGET command */
put "quit";
run;
filename doftp pipe %unquote(%str(%')ftp -n -s:"&ftpcmds" &host%str(%'));
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.
Date Modified: | 2010-09-10 09:17:16 |
Date Created: | 2009-05-27 12:13:14 |
Operating System and Release Information
SAS System | Base SAS | z/OS | | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
OpenVMS VAX | | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
Microsoft Windows XP 64-bit Edition | | |
Microsoft® Windows® for x64 | | |
OS/2 | | |
Microsoft Windows 95/98 | | |
Microsoft Windows 2000 Advanced Server | | |
Microsoft Windows 2000 Datacenter Server | | |
Microsoft Windows 2000 Server | | |
Microsoft Windows 2000 Professional | | |
Microsoft Windows NT Workstation | | |
Microsoft Windows Server 2003 Datacenter Edition | | |
Microsoft Windows Server 2003 Enterprise Edition | | |
Microsoft Windows Server 2003 Standard Edition | | |
Microsoft Windows Server 2008 | | |
Microsoft Windows XP Professional | | |
Windows 7 Enterprise 32 bit | | |
Windows 7 Enterprise x64 | | |
Windows 7 Home Premium 32 bit | | |
Windows 7 Home Premium x64 | | |
Windows 7 Professional 32 bit | | |
Windows 7 Professional x64 | | |
Windows 7 Ultimate 32 bit | | |
Windows 7 Ultimate x64 | | |
Windows Millennium Edition (Me) | | |
Windows Vista | | |
64-bit Enabled AIX | | |
64-bit Enabled HP-UX | | |
64-bit Enabled Solaris | | |
ABI+ for Intel Architecture | | |
AIX | | |
HP-UX | | |
HP-UX IPF | | |
IRIX | | |
Linux | | |
Linux for x64 | | |
Linux on Itanium | | |
OpenVMS Alpha | | |
OpenVMS on HP Integrity | | |
Solaris | | |
Solaris for x64 | | |
Tru64 UNIX | | |