DATA Step, Macro, Functions and more

FTP connections fails, how to define this?

Reply
Regular Contributor
Posts: 161

FTP connections fails, how to define this?

Hi All,
So I use standard FTP connections for accessing to remote files:
Smth. like this:

filename indir ftp '' user='username' pass='xxxx' host='yyyy' DIR;

data _null_;
infile indir;
input;
%put _infile_;
run;

Sometimes connections fails and notes throws to the log:
NOTE: <<< 421 Service not available, closing control connection.

So can I somehow indicate if such situations happens(if connections fails)?
I tried to compare global macro vars which creates if such situation occur with gl. macro vars which creates if file loaded successfully, but looks like they are the same.
May be the only one way is to get target file size, if it 0 then attempt is not successful, but must be some more clever and simple way to resolve this problem.
So how can I know that ftp connections were finished successfully?

Thanks!
Trusted Advisor
Posts: 1,301

Re: FTP connections fails, how to define this?

Not sure if this will aide you since i do not have a ftp with which to verify but you could try to use fileref function:

%macro check_ftp_connection(inf=);
%if %sysfunc(fileref(&inf)) ne 0 %then
%put %sysfunc(sysmsg());
%mend;

filename indir ftp user='user' pass='pass' host='host' dir;

%check_ftp_connection(inf=indir);

Since you said it is not generating a error I am not sure that this will benefit. Message was edited by: Fried Egg
Regular Contributor
Posts: 161

Re: FTP connections fails, how to define this?

Thanks Fried!
But the file creates just with 0 length, so such functionality isn't suitible.

I rid of this problem by using such code:

data test;
infile indir(filename);
input;
a='0';
%put _infile_;
run;

If record_count>0 then %put ok %else %put error;

But I still think that must be some better solution.

Anyway thanks!
Super User
Posts: 10,041

Re: FTP connections fails, how to define this?

You need a auto macro variable to check the status of filename statement.
[pre]
filename indir ftp '' user='username' pass='xxxx' host='yyyy' DIR;

data _null_;
infile indir;
input;
%put _infile_;
%put return code of filename statement : &sysfilrc ;
run;
[/pre]



Ksharp
Ask a Question
Discussion stats
  • 3 replies
  • 139 views
  • 0 likes
  • 3 in conversation