BookmarkSubscribeRSS Feed
MariaD
Barite | Level 11

Hi folks,

 

I tried to transfer a file using FILENAME SFTP. I tested my credential and access directly from SAS Server (using PuTTY with SFTP command) and works fine. 

 

I'm running the following code:

 

filename server sftp "TEST.txt"  host='XXX.XX.XX.XX'
cd='folder' user='myUser' optionsx='-pw "myPass"';  

data _null_;
infile "/folder_on_SASSERver/file.txt" recfm=n ;
input x $char1. @@;
file server recfm=s ;
put x $char1. @@;
run;

The file in "infile" sentence is located on SAS Server, I double check the path and it's correct.

 

But the following errors appears:

 

ERROR: Physical file does not exist, /folder_on_SASSERver/file.txt.
NOTE: sftp: illegal option -- pusage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]            [-o ssh_option] [-P 
      sftp_server_path] [-R num_requests]            [-S program] [-s subsystem | sftp_server] host       sftp [user@]host[:file 
      ...]       sftp [user@]host[:dir[/]]       sftp -b batchfile [user@]host
NOTE: cd "folder"
ERROR: Directory or file TEST.txt doesn't exist.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           1.50 seconds
      cpu time            0.00 seconds

Any idea why it's happens?

 

Regards. 

6 REPLIES 6
SASJedi
Ammonite | Level 13

Looks like your FILENAME SFTP statement syntax doesn't match the docs, and your DATA step is trying to read a local file that doesn't exist. 

First, test to ensure the local file exists:

data _null_;
   /* Verify the file you are reading from is available on the SAS server */
   infile "~/test.txt" truncover;
   /* Read a record from source */
   input;
   /* Write the record to the log */
   put _infile_;
run;

Review the log to ensure you are reading the file correctly. Fiddle with this code until you get it to work.

 

Next, modify the code to write to the SFTP location instead of the log:

Try something like this:

filename outfile sftp "/user/myfolder/text.txt"  host='XXX.XX.XX.XX' user='myUser' optionsx='-pw "myPass"' ;   

data _null_; /* Read from file on the SAS server */ infile "~/test.txt" truncover;
input; /* Write the record to SFTP destination file */ file myFolder; put _infile_; run;

This should help you isolate the problem and get things working more quickly. Let me know how it goes!

May the SAS be with you!

Check out my Jedi SAS Tricks for SAS Users
MariaD
Barite | Level 11

Thanks @SASJedi , I double check and the file on SAS server exist and it's in the correct location but still the same error appears.

 

It's like the process tried to read from SFTP instead of write:

 

filename archivo sftp "/my directory/TEST_DESCONSIDERAR.txt"  host='XX.XX.XX.XX'
user='myuser' optionsx=' -pw "myPassword"' DEBUG recfm=v;  

filename test '/work_SAS/test.txt';

data _null_;
infile test recfm=n ;
input;
file archivo  ;
put _infile_;
run;
NOTE: UNBUFFERED is the default with RECFM=N.
NOTE: The infile TEST is:
      Filename=/work_SAS/test.txt,
      Owner Name=sas,Group Name=sas,
      Access Permission=-rw-r--r--,
      Last Modified=17Feb2021:12:26:23,
      File Size (bytes)=5

NOTE: unknown option -- wusage: sftp [-46aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]          [-D sftp_server_path] [-F 
      ssh_config] [-i identity_file]          [-J destination] [-l limit] [-o ssh_option] [-P port]          [-R num_requests] 
      [-S program] [-s subsystem | sftp_server]          destination
NOTE: cd "/my directory"
ERROR: Directory or file /my directory/TEST_DESCONSIDERAR.txt doesn't exist.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           1.50 seconds
      cpu time            0.00 seconds

Thanks,

 

Kurt_Bremser
Super User

The ERROR is about the remote file, and it cannot "find" it because it cannot establish the SFTP connection.

And that happens because you try to use an invalid option.

MariaD
Barite | Level 11

Thanks @Kurt_Bremser . So, the optionsx=' -pw' is not allow?

 

Regards,

Kurt_Bremser
Super User

Please read the second paragraph of my previous post.

There I have explained that the external sftp program (which SAS uses) does not have such an option, and why such an option can not exist in the first place.

Kurt_Bremser
Super User

First of all, when SAS tells you a file is not there, it's not there, period. This may have multiple reasons, correct spelling being one of them (UNIX is case sensitive, so EVERY SINGLE character must be spelled correctly upper- or lowercase). Did you determine the path to the file by logging on to the server via SSH and navigating to the directory, or did you take it from the Files section in EG? The Files in EG usually start at your home directory ($HOME).

 

Second, FILENAME SFTP does not support passwords in any way. You MUST set up passwordless authentication (public/private key) before you can use SFTP from SAS.

The UNIX sftp program does not have an option to supply passwords on the commandline, for security reasons (commandlines of processes are viewable by anyone on the system).

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 6226 views
  • 0 likes
  • 3 in conversation