Statements |
Valid: | anywhere |
Category: | Data Access |
Syntax |
FILENAME fileref SFTP 'external-file' <sftp-options>; |
is a valid fileref.
Tip: | The association between a fileref and an external file lasts only for the duration of the SAS session or until you change it or discontinue it with another FILENAME statement. You can change the fileref for a file as often as you want. |
specifies the access method that enables you to use Secure File Transfer Protocol (SFTP) to read from or write to a file from any host computer that you can connect to on a network with an OpenSSH SSHD server running.
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 about specifying the physical names of external files, see the SAS documentation for your operating environment.
Tip: | If you are not transferring a file but performing a task such as retrieving a directory listing, then you do not need to specify an external filename. Instead, put empty quotation marks in the statement. |
Tip: | You can associate a fileref with a single file or with an aggregate file storage location. |
specifies details that are specific to your operating environment such as file attributes and processing attributes.
Operating Environment Information: For more information about some of these SFTP options, see the SAS documentation for your operating environment.
SFTP Options |
specifies the fully qualified pathname and the filename of the batch file that contains the SFTP commands. These commands are submitted when the SFTP access method is executed. After the batch file processing ends, the SFTP connection is closed.
Requirement: | The path must be enclosed in quotation marks. |
Tip: | After the batch file processing ends, the SFTP connection is closed and the filename assignment is no longer available. If subsequent DATA step processing requires the FILENAME SFTP statement, then another FILENAME SFTP statement is required. |
Featured in: | Using a Batch File |
issues a command that changes the working directory for the file transfer to the directory that you specify.
writes informational messages to the SAS log.
enables you to access directory files. Specify the directory name in the external-file argument. You must use valid directory syntax for the specified host.
Interaction: | The CD and DIR options are mutually exclusive. If both are specified, SFTP ignores the CD option and SAS writes an informational note to the log. |
Tip: | If you want SFTP to create the directory, then use the NEW option in conjunction with the DIR option. The NEW option will be ignored if the directory exists. |
Tip: | If the NEW option is omitted and you specify an invalid directory, then a new directory will not be created and you will receive an error message. |
where host is the network name of the remote host with the OpenSSH SSHD server running.
You can specify either the name of the host (for example, server.pc.mydomain.com) or the IP address of the computer (for example, 2001:db8::).
where lrecl is the logical record length of the data.
Default: | 256 |
Interaction: | Alternatively, you can specify a global logical record length by using the LRECL= system option. |
issues the LS command to the SFTP server. LS returns the contents of the working directory as records with no file attributes.
Restriction: | The LS option will not display files with leading periods, for example .xAuthority. |
Interaction: | The LS and LSA options are mutually exclusive. If you specify both options, the LSA option takes precedence. |
Tip: | To return a listing of a subset of files, use the LSFILE= option in addition to LS. |
issues the LS command to the SFTP server. LSA returns all the contents of the working directory as records with no file attributes.
Interaction: | The LS and LSA options are mutually exclusive. If you specify both options, the LSA option takes precedence. |
Interaction: | To display files without leading periods, for example .xAuthority, use the LS= option. |
Tip: | To return a listing of a subset of files, use the LSFILE= option in addition to LSA. |
in combination with the LS option, specifies a character string that enables you to request a listing of a subset of files from the working directory. Enclose the character string in quotation marks.
transfers multiple files, similar to the SFTP command MGET.
Tip: | The whole transfer is treated as one file. However, as the transfer of each new file is started, the EOV= variable is set to 1. |
specifies that you want SFTP to create the directory when you use the DIR option.
Restriction: | The NEW option is not available under z/OS. |
Tip: | The NEW option will be ignored if the directory exists. |
specifies SFTP configuration options such as port numbers.
specifies the location of the SFTP executable if it is not installed in the PATH or $PATH search path.
Tip: | It is recommended that the OpenSSH "SFTP" executable or PUTTY "PSFTP" executable be installed in a directory that is accessible via the PATH or $PATH search path. |
where recfm is one of two record formats:
is fixed-record format. Thus, all records are of size LRECL with no line delimiters.
is variable-record format (the default). In this format, records have varying lengths, and they are separated by newlines. Data is transferred in image (binary) mode.
Default: | V |
specifies the user name.
Requirement: | The username is required by the PUTTY client on the Windows host. |
Tip: | The username is not typically required on LINUX or UNIX hosts when using public key authentication. |
Tip: | Public key authentication using an SSH agent is the recommended way to connect to a remote SSHD server. |
specifies the SFTP response time in milliseconds.
Default: | 1,500 milliseconds |
Tip: | If you receive a timeout message in the log, use the WAIT_MILLISECONDS option to increase the response time. |
Details |
The Secure File Transfer Protocol (SFTP) provides a secure connection and file transfers between two hosts (client and server) over a network. Both commands and data are encrypted. The client machine initiates a connection with the remote host (OpenSSH SSHD server).
With the SFTP access method, you can read from or write to any host computer that you can connect to on a network with an OpenSSH SSHD server running. The client and server applications can reside on the same computer or on different computers that are connected by a network.
Specific implementation details are dependent on the OpenSSH SSHD server version and how that site is configured.
The SFTP access method relies on default send and reply messages to OpenSSH commands. Custom installs of OpenSSH that modify these messages will disable the SFTP access method.
You must have the applicable client software installed to use the SFTP access method. The SFTP access method supports only the following SSH clients.
OpenSSH - UNIX
PUTTY - Windows
Note: Password validation is not supported for the SFTP access method.
Note: Public key authentication using an SSH agent is the recommended way to connect to a remote SSHD server.
Note: If you have trouble running the SFTP access method try to manually validate SFTP client access to an OpenSSH SSHD server without involving the SAS system. Manually validating SFTP client access without involving the SAS system will ensure that your SSH/SSHD configuration and key authentication is setup correctly.
The SFTP access method supports only the following prompts. Changing the prompt will disable the SFTP access method.
For OpenSSH:
sftp> | |
sftp > |
For PUTTY:
psftp> |
Comparisons |
As with the SFTP get and put commands, the SFTP 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.
Examples |
This example reads a file called test.dat using the SFTP access method after connecting to the SSHD server a standard port:
filename myfile sftp '/users/xxxx/test.dat' host="unixhost1"; data _null_; infile myfile truncover; input a $25.; run;
This example reads a file called test.dat using the SFTP access method after connecting to the SSHD server at port 4117:
filename myfile sftp '/users/xxxx/test.dat' host="unixhost1" options="-oPort=4117"; data _null_; infile myfile truncover; input a $25.;; run;
This example writes a file called test.dat using the SFTP access method after connecting a Windows PUTTY client to the SSHD server with a userid of userid:
filename outfile sftp '/users/xxxx/test.dat' host="unixhost1" user="userid"; data _null_; file outfile; do i=1 to 10; put i=; end; run;
This example reads the files test.dat and test2.dat from a directory on the remote host.
filename infile sftp '/users/xxxx/' host="unixhost1" dir; data _null_; infile infile(test.dat) truncover; input a $25.; infile infile(test2.dat) truncover; input b $25.; run;
In this example, when the INFILE statement is processed, the batch file associated with the FILENAME SFTP statement, sftpcmds, is executed.
filename process sftp ' ' host="unixhost1" user="userid" batchfile="c:/stfpdir/sftpcmds.bat"; data _null_; infile process; run;
See Also |
Statements: | |||||||||||||||
Barrett, Daniel J., Richard E. Silverman, and Robert G. Byrnes. 2005. SSH, The Secure Shell: A Definitive Guide. Sebastopol, CA: O'Reilly |
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.