Using the FILENAME Statement or the FTP Utility for Foreign Files and Transport Files


Example: Using the FILENAME Statement to Specify Transport File Attributes for all Target Machines

Caution  

Use the FILENAME statement only for transport files, not foreign files.

Here is an example of using the FILENAME statement with the FTP access method to specify file attributes and to transfer a transport file over the network to a target machine:

 filename tranfile ftp 'tport.dat' lrecl=80 blocksize=8000   recfm=f cd='mydir' host='myhost.mycompany.com'   user='myuser' pass='mypass'   rcmd='site umask 022' recfm=s; 

The FILENAME statement specifies the fileref TRANFILE, which specifies the external file TPORT.DAT for transfer over the network. FTP options specify values for the record attributes: record length, block size , and record format. Also, FTP options identify the location for the file transfer on the target machine and the user ID and password that permit access to the target machine. Finally, the file mode creation mask on the target machine and a binary transfer are specified. For complete information, see the FILENAME Statement, FTP Access Method in SAS Language Reference: Dictionary and the companion documentation that is appropriate to your operating environment.

Note  

Besides the FTP access method, you can also use the SOCKET, URL, or SMTP access method in the FILENAME statement. FTP directs the file to a hard disk, SOCKET directs the file to a TCP/IP port, URL directs the file to the Web, and SMTP directs the file to e-mail. For complete information, see the FILENAME Statement, SOCKET Access Method in SAS Language Reference: Dictionary ; the FILENAME Statement, URL Access Method in SAS Language Reference: Dictionary ; and the FILENAME Statement, SMTP Access Method in SAS Language Reference: Dictionary .

Using FTP to Transfer Files in Foreign Format and Transport Files Across the Network

FTP is a user interface to the File Transfer Protocol. FTP copies files across a network connection between the source machine and a target machine. FTP runs from the initiating machine, which can be either the source machine or the target machine.

In order to transfer a file to a target machine across a network, a binary (or image) format transfer must be specified. This format guarantees a consistent file structure for any operating environment that runs SAS. For example, you must use the FTP BINARY command to declare binary format. For typical FTP command syntax, see "Example: Using FTP to Transfer Foreign Files and Transport Files" on page 40.

Transferring a file in ASCII format places extra characters in the transport file on the target machine. Usually, these characters are line feeds, carriage returns, end-of-record markers, and other characters that some operating environments use to define file characteristics.

Target machines that run SAS expect a transport file to be formatted in a certain structure, without these characters. The introduction of these characters into a file causes corruption, which prevents the file from being successfully restored at the target machine. Error messages usually warn of file corruption. For information about file corruption and how to recover from this condition, see Chapter 12, "Preventing and Fixing Problems," on page 67.

Note  

SAS 6.11 through 9 support the FILENAME statement with the FTP access method, which specifies file attributes for file transfer. Releases prior to 6.11 do not support the FILENAME statement with the FTP access method.

Using a Magnetic Medium for Tansferring Files in Foreign Format and Transport Files

When transferring a transport file by means of tape, always use an unlabeled tape. Although using a standard labeled tape is possible, it usually requires extra work to read the file at the target machine.

Also, if the transport file exceeds the capacity of one tape, then problems might occur during the restoration process. Rather than using multi-volume tapes, you should divide the original library into two or more libraries and create a separate tape for each one. The original library can be rebuilt at the target machine.

At the source machine, use the LIBNAME statement to assign the transport file to a magnetic medium.

Examples:

UNIX

libname tranfile xport '/dev/tape';

Windows

libname tran xport 'a:\test';

Specification of the file path varies by operating environment.

The method used to move the transport file to a physical tape also varies by operating environment.

A UNIX example follows :

 dd if=tranfile of=/dev/tape1 bs=8000; 

The UNIX dd command copies the specified input file to the specified output device. Block size is 8000.

At the target machine, you must copy the transport file from tape to disk.

A UNIX example follows:

 dd if=/dev/tape1 of=tranfile bs=8000; 

At the target machine, you use the LIBNAME statement to translate the transport file to native format, assigning the resulting translated file to a specific file location.

A UNIX example follows:

 libname tranfile xport '/dev/tape1'; 

Example: Using FTP to Transfer Foreign Files and Transport Files

You transfer a foreign file in the same way that you transfer a transport file. The only difference between the two is the filename. SAS appends a transport filename with an appropriate member type extension, such as .DAT for a data set. A file that was created with CEDA features is appended with an appropriate SAS 9 or 8 filename extension; for example, .SAS9BDAT for a data set.

In the following examples, TRANFILE specifies the name of the transport file that is transferred across the network. TARGET specifies the destination for the file in foreign format or the transport file on the target machine.

Example Code 6.1 on page 40 shows FTP commands used at the source machine to put a foreign file or a transport file on the target machine:

Example Code 6.1: FTP PUT Commands
start example
 /* putting transport file on the target machine */   > open  target-machine  > binary   > put tranfile target-machine-filename   > close   > quit 
end example
 

Example Code 6.2 on page 41 shows FTP commands used at the target machine to get a foreign file or a transport file from the source machine:

Example Code 6.2: FTP GET Commands
start example
 /* At the target machine, getting transport file from */ /* the source machine */   > open  source-machine  > binary   > get tranfile source-machine-filename   > close   > quit 
end example
 

If you have access to a UNIX system, see the ftp (1) manual page for more details.

Note  

In order to copy a file with the FTP put command to a server location, you must have write permission to the target location on the server. Because a local user's permission to put a file at a server location is uncertain , it is recommended that the remote user use the FTP get command to obtain the file from the client instead. The local user must give read and write permission to the file that the remote user accesses .

The following code shows an example of user JOE at the target machine getting two transport files from an OpenVMS Alpha source machine:

Example Code 6.3: Typical FTP Session
start example
 hp> ftp myhost.mycompany.com  [1] Connected to myhost.mycompany.com 220 myhost.mycompany.com MultiNet FTP Server Process V4.0(15)   at Mon 13-Jan-03 12:59PM-EDT Name (myhost.mycompany.com:): joe 331 User name (joe) ok. Password, please. Password: 230 User JOE logged into DISK01:[JOE] at Mon 13-Jan-03   12:59PM-EDT, job 27a34cef. Remote system type is VMS. ftp> cd [.xpttest]  [2] 250 Connected to DISK01:[JOE.XPTTEST]. ftp> binary 80  [3] 200 Type I ok. ftp> get xptds.dat xptds.dat  [4] 200 Port 14.83 at Host 10.26.2.45 accepted. 150 IMAGE retrieve of DISK01:[JOE.XPTTEST]XPTDS.DAT;1 started. 226 Transfer completed. 1360 (8) bytes transferred.  [5] 1360 bytes received in 0.02 seconds (87.59 Kbytes/s) ftp> get xptlib.dat xptlib.dat  [6] 200 Port 14.84 at Host 10.26.2.45 accepted. 150 IMAGE retrieve of DISK01:[JOE.XPTTEST]XPTLIB.DAT;1 started. 226 Transfer completed. 3120 (8) bytes transferred.  [7] 3120 bytes received in 0.04 seconds (85.81 Kbytes/s) ftp> quit  [8] 
end example
 
[1]  

From an HP-UX operating environment, the user invokes FTP to connect to the OpenVMS Alpha operating environment MYHOST.MYCOMPANY.COM.

[2]  

After a connection is established between the HP-UX source machine and the OpenVMS Alpha target machine, at the FTP prompt, the user JOE changes to the directory on the target machine that contains transport file XPTTEST.

[3]  

Transport file attributes BINARY 80 indicate that the OpenVMS transport file be transferred to the source machine in BINARY format in 80-byte records.

[4]  

The FTP command gets the transport file named XPTDS.DAT from the target machine and copies it to a new file that has the same name, XPTDS.DAT, in the current directory.

[5]  

Messages indicate that the transfer was successful and that the length of the transport file was 1360 bytes.

[6]  

The FTP command gets another transport file named XPTLIB.DAT from the target machine and copies it to a new file that has the same name, XPTLIB.DAT, in the current directory.

[7]  

Messages indicate that the transfer was successful and that the length of the transport file was 3120 bytes.

[8]  

The user quits the FTP session.




Moving and Accessing SAS 9.1 Files
Moving And Accessing SAS 9.1 Files
ISBN: 1590472306
EAN: 2147483647
Year: 2004
Pages: 109
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net