Question on using SFTP to rename a file at remote SFTP server after getting the file

Reply
New Contributor
Posts: 2

Question on using SFTP to rename a file at remote SFTP server after getting the file

Hi, I need to develop a SAS program to get a file from an remote SFTP server and rename the file after download the file. I can get the file but don't know how to send the UNIX rename command to the remote SFTP server to rename the file. Any suggestion? 

 

Following is my code that I have developed and it works well:

 

Filename SITE1 SFTP "reports/Market_Summary_date..csv"
Host="142.199.199.199" user="user1" ;

data WORK.Market_DATA ;
%let _EFIERR_ = 0; 
infile site1 delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2;
informat REPORT_DATE yymmdd10. ;

format REPORT_DATE yymmdd10. ;

input
       REPORT_DATE;

if _ERROR_ then call symputx('_EFIERR_',1);

run;

Regular Contributor
Posts: 212

Re: Question on using SFTP to rename a file at remote SFTP server after getting the file

Hi mate.

 

You can use the filename statement to rename the file using a shell script command "mv".

 

you can use the following sintax:

 

filename myfile pipe "mv myfile.txt newfile.txt";

/*or you can use the X command*/

x "mv myfile.txt newfile.txt";

Once you have permission to execute shell scripts you can use filename, call system, or x command to execute Shell scripts from SAS.

 

Check out some Shell commands or Executing Operating System Commands from Your SAS Session;

 

Hope this helps

New Contributor
Posts: 2

Re: Question on using SFTP to rename a file at remote SFTP server after getting the file

Hi, thank you for sharing the code with me.. I have some problems on using the Filename  myfile Pipe statement.

 

If I use this 

 

Filename SITE4 PIPE 'mv reports/Market_Summary_20151102.csv reports/Market_Summary_20151102.done'
  Host="142.199.199.199" user="userid" ;
run;

 

I received an error message tha Host and user are invalid option. It seems to me that host and user cannot use with pipe. If I don't define for SFTP server IP and user id, how can I rename the file

 

If I use this 

 

Filename SITE4 PIPE 'mv reports/Market_Summary_20151102.csv reports/Market_Summary_20151102.done' ;
run;

 

I received an error message that I have insufficient authority.  

 

Please advise and thank you for your help...

Regular Contributor
Posts: 212

Re: Question on using SFTP to rename a file at remote SFTP server after getting the file

Hi mate,

Once you are in the enviroment of this host you don't need to use these options.

Your SAS is connected in this host, or it is another server ?

 

These are the questions that you might answer to select the option that you have to use.

Pipe is used to the server you are connected.

 

Maybe you should use instead of pipe use sftp and do the same.

 

Try this: FILENAME Statement, SFTP Access Method

 

Hope this helps

Ask a Question
Discussion stats
  • 3 replies
  • 277 views
  • 0 likes
  • 2 in conversation