DATA Step, Macro, Functions and more

Copy files from SAS to FTP serwer

Reply
Contributor
Posts: 26

Copy files from SAS to FTP serwer

Hi,
I would like to copy some files from my SAS server (UNIX) to another FTP host.

The connection beetwen my server and FTP is open (I tried 'ftp xxx.xxx.xxx.xxx' command in PUTTY).
Trusted Advisor
Posts: 2,113

Re: Copy files from SAS to FTP serwer

You could use the "X" command to shell out to unix and then have a script that does the FTP.

Perhaps you could be more specific about what you are trying to accomplish.
Super Contributor
Super Contributor
Posts: 3,174

Re: Copy files from SAS to FTP serwer

When copying "SAS files" to another system, there may be OS platform considerations, which warrant your review of the SAS and CEDA topic - search the SAS support website for technical reference documents, as well as SAS-hosted documentation.

And, consider using the FILENAME FTP technical approach with SAS - again check the SAS support website for DOC and supplementation technical / conference papers. Do consider that there are OS-specific "companion" guides which may have supplemental info on using FILENAME and the FTP engine.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

sas file transfer ceda site:sas.com

filename ftp engine file transfer site:sas.com
Super User
Posts: 9,676

Re: Copy files from SAS to FTP serwer

What problem did you meet?
What type of files are you need to transfer?If it is dataset or some SAS members file,It better to make a transported file by using proc cport / proc copy.
If you only want to transfer some ASIIC files.Just to use some ftp command.

1)Login UNIX server
2)Enter the directory which contains the files you need to transfer.
3)ftp 10.1...enter your username password
4)Enter the directory in FTP you want to locate.
5)Type command ' binary 80'
6)Type command 'put lucas.txt'
7)Type command 'bye'



Ksharp
Contributor
Posts: 26

Re: Copy files from SAS to FTP serwer

Hi Ksharp,

I would like to do something similar to your solution.
But I want to do this automatically.
Is it possible to have a script on AIX server that does the FTP commands?
Super User
Posts: 9,676

Re: Copy files from SAS to FTP serwer

Sorry.
I have not such experience.Maybe Google would help you a little bit.
Or just write some UNIX shell script.
Contributor
Posts: 26

Re: Copy files from SAS to FTP serwer

Hi,
I solved my problem in this way:

filename csvFTP ftp "&target_path_ftp/&file_name..csv"
host="&host"
user="&user" password="&pass';

proc export data=work.MyTable
outfile= csvFTP
dbms=dlm replace;
delimiter=';';
run;


But it isn't exactly what I want...

Does anyone can help me to do this with "X" command?

I need to copy a .csv file from my SAS server (/home/sasuser/test.csv ) to FTP sever (/home/ftpuser).
Super Contributor
Super Contributor
Posts: 3,174

Re: Copy files from SAS to FTP serwer

Suggest searching the SAS support http://support.sas.com/ website or the forum archives -- you will want to focus on the SAS "companion" documentation for your OS.

Scott Barry
SBBWorks, Inc.

Google advanced search argument, this topic / post:

x command site:sas.com
Contributor
Posts: 26

Re: Copy files from SAS to FTP serwer

Hi,
unfortunately I can't use X commands :/
Is there any way to copy files from SAS to FTP server?
The files are zip archives.
Valued Guide
Posts: 2,175

Re: Copy files from SAS to FTP serwer

Use that FTP FILENAME statement that worked for PROC export but refer to it in a data step. For binary files, use $char format in PUT statements
Contributor
Posts: 26

Re: Copy files from SAS to FTP serwer

Sorry, but I don't understand what you mean :/ Could you write an example ? Message was edited by: Lucas
Valued Guide
Posts: 2,175

Re: Copy files from SAS to FTP serwer

Lucas

before writing to FTP, practise in using SAS to copy files. Here is example 1[pre]data _null_ ;
infile 'a simple text file.txt' lrecl=10000 ;
file 'a copy.txt' lrecl=10000 ;
input ;
put _infile_ ;
run; [/pre]* notice that lrecl. It ensures you use up to 10000 of each line.
Example 2: using filename statements ; [pre]filename ffrom 'a simple text file.txt' lrecl=10000 ;
filename fileTO 'a copy.txt' lrecl=10000 ;
data _null_ ;
infile ffrom ;
file fileto ;
input ;
put _infile_ ;
run; [/pre] * see how similar. Just using file refs instead;
* next Example 3 making a binary copy;[pre]filename ffrom 'a binary file.stc' lrecl=80 recfm=F ; [/pre] * and fill it with a cport file ;[pre]proc cport data= sashelp.class file= ffrom;
run ;[/pre] * might as well be something familiar ;[pre]filename fileTO 'copy of cport.stc' lrecl=80 recfm= f ;
data _null_ ;
infile ffrom pad ;
file fileto ;
input ;
put _infile_ ;
run;[/pre]* and lets check it is OK ;[pre]proc cimport lib= work file= fileto ;
run; [/pre] * beginnng to look familiar? ;
* I guess you noticed an extra thing on the INFILE statement. That PAD option ensures the end-of-file coming inside the multiple of 80 will not cause trouble;
* finally the FTP Example ;
* just use your FTP filename statement with, perhaps no more;[pre]filename myFTP ftp "&target_path_ftp/&file_name..stc" binary lrecl= 80 recfm=F ;
* you already have a binary file defined;
data _null_ ;
infile ffrom pad ;
file fileto ;
input ;
put _infile_ ;
run;[/pre] * and you will have to try that yourself;
OK The transfer over FTP should define binary in the filename statement for a binary file especially when transferring to a different encoding system (like zOS in ebcdic from an ascii environment like windows or unix). You may want to transfer only text. In that case drop the RECFM= and set LRECL= to a size at least large enough for your widest line.
is that enough example?

good luck

peterC

doc for filenameFT is at http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000178980.htm
Contributor
Posts: 26

Re: Copy files from SAS to FTP serwer

Peter.C.

Thanks! Your example is very comprehensible. And it works Smiley Happy

I also write a simple script which can be executed directly from AIX server. Maybe it would be useful for someone.



#!/bin/ksh

HOST='xx.xx.xx.xxx'
USER='user'
PASSWD='pass'

ftp -n $HOST <<!EOF
quote USER $USER
quote PASS $PASSWD
prompt
put filename.zip
bye
!EOF
Ask a Question
Discussion stats
  • 12 replies
  • 2998 views
  • 0 likes
  • 5 in conversation