DATA Step, Macro, Functions and more

How to trnsfer file from Windows to Unix

Reply
Frequent Contributor
Posts: 117

How to trnsfer file from Windows to Unix

I have tried to create a program to trasfer files from my local directory (windows) to SAS (Unix) server. BUt i am unable to get the file, and i am getting note in log file saying that connection timed out . Please give any sugestions on this. Below is the code i have written.

%let ftpcmds= C:\WINDOWS\system32\cmd.exe;
%let host=&host;             
%let userid=&userid;             
%let ftppwd=&ftppwd;              
%let xfermode=binary;                
%let homedir= &source ;   

%let filename=&filename;
%let cmd=mput;                    
%let thefile=⌖


%Macro ftp ;

filename ftpcmds "&ftpcmds";
data _null_;
   file ftpcmds pad lrecl=80;
   put "user &userid &ftppwd";
   put "&xfermode";
   %if %eval(&homedir) %then %do;
    put "cd &homedir";
    put "bin";
    put "prompt";
    put "lcd &thefile";
    put "&cmd &filename ";
   %end;
   %else %do;
       put "File Doesn't exist";
   %end;
run;

filename doftp pipe "ftp -n &host < &ftpcmds";
data _null_;
infile doftp;
input;
put _infile_;
run;

%mend;

%ftp;

Super User
Super User
Posts: 7,997

Re: How to trnsfer file from Windows to Unix

Hi,

And what are the results of running through normal debugging techniques?  I.e.

1) put the ftp plus commands into the windows command window and run them, does it work there?

2) If so, then write the same commands into a datastep and execute in SAS, does it work there.

3) If it does work there, add in the macro code and use the options mlogic mprint symblogen, to see exactly what commands are being sent out, do these match?

Once you run through these steps you will see where it falls over and what is missing, maybe some permissions perhaps either in Win or Unix or SAS.

But to isolate something you need to start small and work up to creating a macro.

Super User
Posts: 7,866

Re: How to trnsfer file from Windows to Unix

I see quite some issues here:

The ftpcmds points to the windows command interpreter, and not to a writable file. If the write actually worked, you borked your system.

%if %eval(&homedir) %then %do;

&homedir is a directory name, which cannot reasonably be evaluated by the %eval function.

Where is your SAS session running? If you have a UNIX SAS server, then the external commands will run on the UNIX platform, no "C:\" etc there.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 117

Re: How to trnsfer file from Windows to Unix

Posted in reply to KurtBremser

SAS session is running on Unix server . and i want to transfer the file existing in my local drive to Unix server. Is there anyway to transfer these files through code..i know that directly i cant use C:\ drive in SAS environment.

Super User
Posts: 7,866

Re: How to trnsfer file from Windows to Unix

First thing: when specifying files to store scripts, you must adhere to the UNIX file system syntax (Unix filesystem - Wikipedia, the free encyclopedia) and make sure that the path points to a location where you have write permission.

Second: to initiate a file transfer between the two platforms from the UNIX side, you need a communications partner waiting for you on the Windows side. If you don't have Microsoft IIS running on Windows, you will need third-party software for this (List of FTP server software - Wikipedia, the free encyclopedia). It is one of the gross shortcomings of Windows that it does not include such essential services out of the box.
Third: when initiating from the UNIX side, you need to GET the files in order to transfer from Windows to UNIX.
Depending on your needs, you may be better off by establishing a shared network location with a samba server on the UNIX side, or use the samba client on UNIX to connect to a Windows share, or use some other means supplied by your IT people.
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Frequent Contributor
Posts: 117

Re: How to trnsfer file from Windows to Unix

Posted in reply to KurtBremser

I will probably recheck everything and let you know the result. Thank you and going to check the steps even suggested by RW9.

Frequent Contributor
Posts: 117

Re: How to trnsfer file from Windows to Unix

Posted in reply to KurtBremser

This is the note i am getting.

ftp: connect: A remote host refused an attempted connect operation.

Not connected.

Not connected.

Not connected.

Not connected.

Interactive mode off.

Super User
Posts: 7,866

Re: How to trnsfer file from Windows to Unix

The first line signals that you supplied a nonexistent hostname, everything else is a consequence of that.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 10,046

Re: How to trnsfer file from Windows to Unix

I am not sure .

filename doftp pipe "ftp -n &host < &ftpcmds";

Why you refer &ftpcmds  to cmd.exe ? Shouldn't  that be a file(contains shell code)  name ?

Ask a Question
Discussion stats
  • 8 replies
  • 824 views
  • 2 likes
  • 4 in conversation