BookmarkSubscribeRSS Feed
Vish33
Lapis Lazuli | Level 10

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;

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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.

Vish33
Lapis Lazuli | Level 10

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.

Kurt_Bremser
Super User

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.
Vish33
Lapis Lazuli | Level 10

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

Vish33
Lapis Lazuli | Level 10

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.

Ksharp
Super User

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 ?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 8 replies
  • 2483 views
  • 2 likes
  • 4 in conversation