BookmarkSubscribeRSS Feed
arunrami
Pyrite | Level 9

Guys , I need to copy file from windows shared network to the unix path , sas running on unix environment,

.

can any one help me with the right syntax we can use for it?? 

 

16 REPLIES 16
JasonDiVirgilio
Quartz | Level 8

Is your windows server mapped/mounted to the Unix server?  Or are you running software like Samba to make the Windows server visible to Unix?  If not, Unix will not be able to "see" the windows server.

Kurt_Bremser
Super User

If you want to run the copy action from a SAS session running on a UNIX server, you need to save the file in Windows to a location that your SAS server can "see", or you need to use a file copy utility (or filename ftp/sftp), and have a FTP/SFTP server program running on the Windows side.

Depending on what you have (and if you can run external commands from your SAS session), we can determine which method to use.

arunrami
Pyrite | Level 9

Thanks @Kurt_Bremser  . 

 

can you please share the document or link where I can find the FTP sytanx for SAS

Kurt_Bremser
Super User

Look in the SAS documentation, section Global Statements:

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=lestmtsglobal&docsetTarge... 

FILENAME SFTP is just two items down in the navigation pane.

Once you have defined a file reference to the FTP source, you can use it as infile in a data step or as datafile in a proc import.

arunrami
Pyrite | Level 9

I have refered one of your previous answer for my problem .

Code is running fine but it is not actually performing the expected operation,. can you please help where i went wrong

%let filename=Arun.csv;
%let username=%sysget(USER);

filename oscmd pipe "sftp &username. windowspath/&filename @unixpath/&filename..dat 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;
JasonDiVirgilio
Quartz | Level 8

I don't see the SFTP hostname in your code.  You might need &username@&hostname .

arunrami
Pyrite | Level 9

NOTE: Compression was disabled for data set WORK.NULL because compression
overhead would increase the size of the data set.
NOTE: The infile OSCMD is:

Pipe command="sftp
N****@\\*****/Arun.csv <<< $'put
**********/Arun.csv' 2>&1"

/bin/ksh: syntax error at line 1 : `<' unexpected
NOTE: 1 record was read from the infile OSCMD.
The minimum record length was 49.
The maximum record length was 49.
NOTE: The data set WORK.NULL has 1 observations and 1 variables.

Kurt_Bremser
Super User

@arunrami wrote:

NOTE: Compression was disabled for data set WORK.NULL because compression
overhead would increase the size of the data set.
NOTE: The infile OSCMD is:

Pipe command="sftp
N****@\\*****/Arun.csv <<< $'put
**********/Arun.csv' 2>&1"

/bin/ksh: syntax error at line 1 : `<' unexpected
NOTE: 1 record was read from the infile OSCMD.
The minimum record length was 49.
The maximum record length was 49.
NOTE: The data set WORK.NULL has 1 observations and 1 variables.


This cannot be the log of may code, as I do not use any INPUT redirection (<), I only redirect stderr to stdout.

 

arunrami
Pyrite | Level 9

Please find this , exactly used your syntax.

intention : need to copy csv file from windows to unix

 

NOTE: Compression was disabled for data set WORK.NULL because compression 
      overhead would increase the size of the data set.
NOTE: The infile OSCMD is:
      
      Pipe command="sftp N**** 
      \\****/Arun.csv
      @/******/Arun.csv 2>&1"

usage: sftp [-1246aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
          [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
          [-o ssh_option] [-P port] [-R num_requests] [-S program]
          [-s subsystem | sftp_server] host
       sftp [user@]host[:file ...]
       sftp [user@]host[:dir[/]]
       sftp -b batchfile [user@]host
NOTE: 7 records were read from the infile OSCMD.
The minimum record length was 32.
The maximum record length was 77.
Tom
Super User Tom
Super User

Make sure you can get the command to run from the command prompt without using SAS at all.

 

The SFTP command is telling you that the syntax of your command is wrong.  It wants these three pieces of information.

 sftp [user@]host[:file ...]

So I would assume that would look like:

sftp myuser@myhost:\\servername\sharename\dirname\filename.ext

Note there is no place to put a password so you either need to have previously shared keys with the host, or use the -i option to specify the file with the user credentials that will let you connect to the host.

 

Kurt_Bremser
Super User

Please post the link of my post where you got the sftp code from. (It's hard for me to find that particular post, as I have dealt with sftp transfers quite often here on the ciommunities)

It may be that the post needs correction.

Kurt_Bremser
Super User

That example was for copying a file from the SAS server to a remote destination. It is not intended for retrieving a dataset.

 

The filename statement for retrieving a file needs to be

filename oscmd pipe "sftp &user.@&host.:&external_path./extfilename. &local_path./&locfilename. 2>&1";

Note that passwordless authentication needs to be set up beforehand. SSH does not support passwords on the commandline, for security reasons.

To make development of the external command easier, I suggest you log ion to your SAS server with SSH yourself and test the command on the commandline till it works there. Note that I work on AIX, and sftp syntax on Linux might be slightly different.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 16 replies
  • 3667 views
  • 4 likes
  • 4 in conversation