BookmarkSubscribeRSS Feed
Lucas
Calcite | Level 5
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).
12 REPLIES 12
Doc_Duke
Rhodochrosite | Level 12
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Ksharp
Super User
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
Lucas
Calcite | Level 5
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?
Ksharp
Super User
Sorry.
I have not such experience.Maybe Google would help you a little bit.
Or just write some UNIX shell script.
Lucas
Calcite | Level 5
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).
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Lucas
Calcite | Level 5
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.
Peter_C
Rhodochrosite | Level 12
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
Lucas
Calcite | Level 5
Sorry, but I don't understand what you mean 😕 Could you write an example ? Message was edited by: Lucas
Peter_C
Rhodochrosite | Level 12
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
Lucas
Calcite | Level 5
Peter.C.

Thanks! Your example is very comprehensible. And it works 🙂

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 6574 views
  • 0 likes
  • 5 in conversation