| FILENAME, FTP Access Method |
Allows you to access remote files using the FTP protocol
| Valid: |
anywhere
|
| Category: |
Data Access
|
|
FILENAME fileref FTP 'external-file'
<ftp-options>;
|
-
fileref
-
is a valid fileref.
-
FTP
-
specifies the access method that enables
you to use file transfer protocol (FTP) to read or write to a file from any
host machine that you can connect to on a network with an FTP server running.
-
'external-file'
-
specifies the physical name of an external
file that you want to read from or write to. The physical name is the name
that is recognized by the operating environment.
Operating Environment Information:
For details on specifying the physical names of external
files, see the SAS documentation for your operating environment.
-
host-options
-
specify host-specific details such as file
attributes and processing attributes.
Operating Environment Information:
For
a list of valid specifications, see the SAS documentation for your operating
environment. ![[cautend]](../common/images/cautend.gif)
-
BLOCKSIZE=blocksize
-
where blocksize is the size
of the data buffer in bytes.
-
CD='directory'
-
issues a command that changes the working
directory for the file transfer to the directory
specified.
-
DEBUG
-
writes to the SAS log informational messages
that are sent to and received from the FTP server.
-
HOST='host'
-
where host
is the network name of the remote host with the FTP server running.
-
LIST
-
issues the LIST command to the FTP server.
LIST returns the contents of the working directory as records that contain
all of the file attributes that are listed for each file.
-
LRECL=lrecl
-
where lrecl is the logical
record length.
-
LS
-
issues the LS command to the FTP server.
LS returns the contents of the working directory as records with no file attributes.
-
LSFILE='character-string'
-
in combination with the LS option, specifies
a character string that allows you to request a listing of a subset of files
from the working directory. Enclose the character string in quotation marks.
-
MGET
-
transfers multiple files, similar to the
FTP command MGET.
-
MPROMPT
-
specifies whether to prompt for confirmation
that a file is to be read, if necessary, when the user executes the MGET option.
-
PASS='password'
-
where password
is the password to use with the user name specified in the USER= option.
-
PROMPT
-
specifies to prompt for the user login password,
if necessary.
-
RCMD= 'command
'
-
where command
is the command to send to the FTP server.
-
RECFM=recfm
-
where recfm
is one of three record formats:
-
RHELP
-
issues the HELP command to the FTP server.
The results of this command are returned as records.
-
RSTAT
-
issues the RSTAT command to the FTP server.
The results of this command are returned as records.
-
S370V
-
indicates that the file being read is in
IBM 370 variable format.
-
S370VS
-
indicates that the file that is being read
is in IBM 370 variable-spanned format.
-
USER='username'
-
where username
is used to log in to the FTP server.
As with the FTP get and put commands, the FTP access method lets
you download and
upload files; however, this method directly reads files into your SAS session
without first storing them on your system.
This example retrieves a directory listing from a host
named mvshost1 for user dilbert, and prompts dilbert for
a password:
filename dir ftp '' ls user='dilbert'
host='mvshost1.mvs.sas.com' prompt;
data _null_;
infile dir;
input;
put _INFILE_;
run;
Note:
The quotation marks are empty because no file
is being transferred; because they are required by the syntax, however, the
statement includes empty quotation marks.
This example reads a file called data in the directory
/u/kudzu/mydata
from the remote UNIX host hp720:
filename myfile ftp 'data' cd='/u/kudzu/mydata'
user='guest' host='hp720.hp.sas.com'
recfm=v prompt;
data mydata / view=mydata; /* Create a view */
infile myfile;
input x $10. y 4.;
run;
proc print data=mydata; /* Print the data */
run;
This example creates a file called test.dat in a directory called
c:\remote
for the user bbailey on the host winnt.pc.
filename create ftp 'c:\remote\test.dat'
host='winnt.pc'
user='bbailey' prompt recfm=v;
data _null_;
file create;
do i=1 to 10;
put i=;
end;
run;
This example reads an S370V-format file from an OS/390
system. See the RCMD= option for more information on RCMD='site rdw'.
filename viewdata ftp 'sluggo.stat.data'
user='sluggo' host='mvshost1'
s370v prompt rcmd='site rdw';
data mydata / view=mydata; /* Create a view */
infile viewdata;
input x $ebcdic8.;
run;
proc print data=mydata; /* Print the data */
run;
This example shows how to login to FTP anonymously,
if the host accepts anonymous logins.
Note:
Some anonymous FTP servers require a password.
If required, your e-mail address is usually used. See PASS=
under FTP-Options.
filename anon ftp '' ls host='130.96.6.1'
user='anonymous';
data _null_;
infile anon;
input;
list;
run;
Note:
The quotation marks following the argument FTP
are empty. A filename is needed only when transferring a file, not when routing
a command. The quotation marks, however, are required.
This example uses the CIMPORT procedure to import a
transport data set from a host named mvshost1
for user calvin. The new data set will reside
locally in the SASUSER library. Note that user and password can be SAS macro
variables. If you specify a full-qualified data set name, use double quotation
marks and single quotation marks. Otherwise, the system will append the profile
prefix to the name that you specify.
%let user=calvin;
%let pw=xxxxx;
filename inp ftp "'calvin.mat1.cpo'" user="&user"
pass="&pw" rcmd='binary'
host='sdcmvs.mvs.sas.com';
proc cimport library=sasuser infile=inp;
run;
This example uses the CPORT procedure to transport a
SAS data library to a host named mvshost1 for
user calvin. It will create a new sequential
file on the host called userid.mat64.cpo with
the recfm of fb, lrecl of 80, and blocksize
of 8000.
filename inp ftp 'mat64.cpo' user='calvin'
pass="xxxx" host='mvhost1'
lrecl=80 recfm=f blocksize=8000
rcmd='site blocksize=8000 recfm=fb lrecl=80';
proc cport library=mylib file=inp;
run;
This example creates a new SAS data library on host
mvshost1. The FILENAME statement assigns a fileref to the
new data set. Note the use of the RCMD= option to specify important file attributes.
The LIBNAME statement uses a libref that is the same as the fileref and assigns
it to the XMPORT engine. The PROC COPY step copies all data sets from the
SAS data library referenced by MYLIB to the XPORT engine. Output from the
PROC CONTENTS step confirms that the copy was successful.
filename inp ftp 'mat65.cpo' user='calvin'
pass="xxxx" host='mvshost1'
lrecl=80 recfm=f blocksize=8000
rcmd='site blocksize=8000 recfm=fb lrecl=80';
libname mylib 'SAS-data-library';
libname inp xport;
proc copy in=mylib out=inp mt=data;
run;
proc contents data=inp._all_;
run;
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.