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;
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.
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.
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.
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.
I will probably recheck everything and let you know the result. Thank you and going to check the steps even suggested by RW9.
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.
The first line signals that you supplied a nonexistent hostname, everything else is a consequence of that.
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 ?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.