This sample illustrates basic usage of the FILENAME statement with the FTP access method.
You can use the code in this sample (on the Full Code tab) to upload and download files to an FTP server. The transfer of ZIP, PDF, or SAS7BDAT files is often called a BINARY transfer. For this type of transfer, make sure that no changes are made to the file structure. Where noted, these samples can be run as is.
You will find examples of the following:
For additional documentation about the FILENAME statement, FTP access method, see SAS 9.4 Statements: Reference, Fourth 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.
********************
Reading text data from an FTP server
********************;
FILENAME ftp1 FTP 'FTP_Engine.txt' HOST='ftp.sas.com'
cd='techsup/download/base' user='anonymous'
pass='your email address goes here' debug;
DATA A ;
INFILE ftp1 missover;
INPUT x :&$50.;
put x=;
run;
*****************************
Retrieve a directory listing from an FTP server
*****************************;
FILENAME ftp1 FTP '' LS HOST='ftp.sas.com'
cd='techsup/download/pc' user='anonymous'
pass='your email address goes here' debug;
data;
infile ftp1 obs=10;
input;
put _infile_;
run;
***************
BINARY TRANSFER (read)
Reading a file with FTP, BINARY:
This is useful if the file needs to remain completely intact.
For example, when moving a ZIP, Excel, or SAS dataset file.
***************;
filename rmt ftp 'EE.zip' host='ftp.sas.com'
user='anonymous' pass='your email address goes here'
cd='/techsup/download/pc' recfm=s debug;
FILENAME lcl 'c:\EE.zip' recfm=n;
DATA _NULL_;
N=1;
INFILE rmt NBYTE=n;
INPUT;
FILE lcl ;
PUT _INFILE_ @@;
RUn;
**************************
BINARY TRANSFER (write)
Writing a file with FTP, BINARY -
(Non-working sample. Must test with your own FTP server and files)
**************************;
filename server ftp 'ADDRESS.XLS' host='server.company.com'
user='userid' pass='password' ;
data _null_;
infile 'c:\address2.xls' recfm=n ;
input x $char1. @@;
file server recfm=s ;
put x $char1. @@;
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.
1 FILENAME ftp1 FTP 'FTP_Engine.txt' HOST='ftp.sas.com' 2 cd='techsup/download/base' user='anonymous' 3 pass=XXXXXXXXXXXXXXXXXXXXX debug; 4 5 DATA A ; 6 INFILE ftp1 missover; 7 INPUT x :&$50.; 8 put x=; 9 run; NOTE: 220 FTP server ready. NOTE: <<< 220 FTP server ready. NOTE: >>> USER anonymous NOTE: <<< 331 Guest login ok, send your complete e-mail address as password. NOTE: >>> PASS XXXXXXXXXXXXXXXXXXX NOTE: <<< 230 Guest login ok, access restrictions apply. NOTE: >>> PORT 10,11,14,22,249,114 NOTE: <<< 200 PORT command successful. NOTE: >>> TYPE A NOTE: <<< 200 Type set to A. NOTE: >>> CWD techsup/download/base NOTE: <<< 250-Please read the file README.txt NOTE: <<< 250- it was last modified on Tue Jun 14 14:06:35 2011 - 57 days ago NOTE: <<< 250 CWD command successful. NOTE: >>> PWD NOTE: <<< 257 "/techsup/download/base" is current directory. NOTE: >>> RETR FTP_Engine.txt NOTE: <<< 150 Opening ASCII mode data connection for FTP_Engine.txt (67 bytes). NOTE: User anonymous has connected to FTP server on Host ftp1.sas.com . NOTE: The infile FTP1 is: Filename=FTP_Engine.txt, Pathname= "/techsup/download/base" is current directory, Local Host Name=d72290, Local Host IP addr=fe80::74d6:b4d9:d096:d04c%11, Service Hostname Name=ftp1.sas.com, Service IP addr=149.173.5.110,Service Name=FTP, Service Portno=21,Lrecl=256,Recfm=Variable x=Congratulations! x=You just read a file from an FTP server with SAS. NOTE: <<< 226 Transfer complete. NOTE: >>> QUIT NOTE: 2 records were read from the infile FTP1. The minimum record length was 17. The maximum record length was 49. NOTE: The data set WORK.A has 2 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 1.53 seconds cpu time 0.06 seconds ------------------------------------------------------------------------------ 10 FILENAME ftp1 FTP '' LS HOST='ftp.sas.com' 11 cd='techsup/download/pc' user='anonymous' 12 pass=XXXXXXXXXXXXXXXXXXXXX debug; 13 data; 14 infile ftp1 obs=10; 15 input; 16 put _infile_; 17 run; NOTE: 220 FTP server ready. NOTE: <<< 220 FTP server ready. NOTE: >>> USER anonymous NOTE: <<< 331 Guest login ok, send your complete e-mail address as password. NOTE: >>> PASS XXXXXXXXXXXXXXXXXXX NOTE: <<< 230 Guest login ok, access restrictions apply. NOTE: >>> PORT 10,11,14,22,249,132 NOTE: <<< 200 PORT command successful. NOTE: >>> TYPE A NOTE: <<< 200 Type set to A. NOTE: >>> CWD techsup/download/pc NOTE: <<< 250-Please read the file README.txt NOTE: <<< 250- it was last modified on Wed Jul 27 21:36:05 2011 - 14 days ago NOTE: <<< 250-Please read the file README.txt.bak NOTE: <<< 250- it was last modified on Tue Dec 2 15:42:54 2008 - 980 days ago NOTE: <<< 250 CWD command successful. NOTE: >>> PWD NOTE: <<< 257 "/techsup/download/pc" is current directory. NOTE: >>> TYPE A NOTE: <<< 200 Type set to A. NOTE: >>> NLST NOTE: <<< 150 Opening ASCII mode data connection for file list. NOTE: <<< 226 Transfer complete. NOTE: User anonymous has connected to FTP server on Host ftp1.sas.com . NOTE: The infile FTP1 is: Filename=, Pathname= "/techsup/download/pc" is current directory, Local Host Name=d72290, Local Host IP addr=fe80::74d6:b4d9:d096:d04c%11, Service Hostname Name=ftp1.sas.com, Service IP addr=149.173.5.110,Service Name=FTP, Service Portno=21,Lrecl=256,Recfm=Variable 91Regbld.exe 92regbld.exe 92regbld_64.exe AMORegistryReader.exe AMOroles.xml CleanAmoHkcu.bat Creatingaclientuserdepot_SAS92.pdf Csidl.zip DLLchecker.zip EE.zip NOTE: >>> QUIT NOTE: 10 records were read from the infile FTP1. The minimum record length was 6. The maximum record length was 34. NOTE: The data set WORK.DATA1 has 10 observations and 0 variables. NOTE: DATA statement used (Total process time): real time 0.52 seconds cpu time 0.10 seconds -------------------------------------------------------------------------------- 18 filename rmt ftp 'EE.zip' host='ftp.sas.com' 19 user='anonymous' pass=XXXXXXXXXXXXXXXXXXXXX 20 cd='/techsup/download/pc' recfm=s debug; 21 22 FILENAME lcl 'c:\EE.zip' recfm=n; 23 24 DATA _NULL_; 25 N=1; 26 INFILE rmt NBYTE=n; 27 INPUT; 28 FILE lcl ; 29 PUT _INFILE_ @@; 30 RUn; NOTE: 220 FTP server ready. NOTE: <<< 220 FTP server ready. NOTE: >>> USER anonymous NOTE: <<< 331 Guest login ok, send your complete e-mail address as password. NOTE: >>> PASS XXXXXXXXXXXXXXXXXXX NOTE: <<< 230 Guest login ok, access restrictions apply. NOTE: >>> PORT 10,11,14,22,249,136 NOTE: <<< 200 PORT command successful. NOTE: >>> TYPE I NOTE: <<< 200 Type set to I. NOTE: >>> CWD /techsup/download/pc NOTE: <<< 250-Please read the file README.txt NOTE: <<< 250- it was last modified on Wed Jul 27 21:36:05 2011 - 14 days ago NOTE: <<< 250-Please read the file README.txt.bak NOTE: <<< 250- it was last modified on Tue Dec 2 15:42:54 2008 - 980 days ago NOTE: <<< 250 CWD command successful. NOTE: >>> PWD NOTE: <<< 257 "/techsup/download/pc" is current directory. NOTE: >>> RETR EE.zip NOTE: <<< 150 Opening BINARY mode data connection for EE.zip (1858310 bytes). NOTE: User anonymous has connected to FTP server on Host ftp1.sas.com . NOTE: The infile RMT is: Filename=EE.zip, Pathname= "/techsup/download/pc" is current directory, Local Host Name=d72290, Local Host IP addr=fe80::74d6:b4d9:d096:d04c%11, Service Hostname Name=ftp1.sas.com, Service IP addr=149.173.5.110,Service Name=FTP, Service Portno=21,Lrecl=256,Recfm=Stream NOTE: UNBUFFERED is the default with RECFM=N. NOTE: The file LCL is: Filename=c:\EE.zip, RECFM=N,LRECL=256,File Size (bytes)=0, Last Modified=10Aug2011:14:25:40, Create Time=13Apr2011:11:09:03 NOTE: <<< 226 Transfer complete. NOTE: >>> QUIT NOTE: 1858310 records were read from the infile RMT. The minimum record length was 1. The maximum record length was 1. NOTE: DATA statement used (Total process time): real time 1.14 seconds cpu time 0.67 seconds
Type: | Sample |
Date Modified: | 2012-01-25 14:44:29 |
Date Created: | 2011-08-10 14:09:13 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | ||
Z64 | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
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 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 for x64 | ||||
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 | ||||
Windows Vista for x64 | ||||
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 | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 8.1 Pro x64 | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 |