I need to use SFTP through a proxy server
I have found following example: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000178980.htm
Example 11: Using a Proxy Server
This example uses a proxy server with the FTP access method. The user ID and password are sent via the proxy server.
filename test ftp ' ' ls
host='proxy.server.xxx.com'
user='userid@ftpservername'
pass='xxxxxx'
cd='pubsdir/';
data _null_;
infile test truncover;
input a $256.;
put a=;
run;
I have following scrip, which works fine but does not use a proxy server:
filename TEST SFTP '/MyFolder/'
DIR FILEEXT LSA
HOST = 'ftpservername'
USER = 'Myuser'
WAIT_MILLISECONDS = 5000
LRECL = 2000
OPTIONS = '-P 2222 -i \\myserver\PrivateKey.ppk -pw "xxxxx"'
DEBUG
;
data _null_;
infile TEST;
input;
FILE 'C:\Myfile.txt' ;
put _infile_;
run;
I need to use a PROXY server with port number 8081.
I thought that I can change the code as follow but cannot figure out where to put the port number for the proxy server.
filename TEST SFTP '/MyFolder/'
DIR FILEEXT LSA
HOST = 'proxy.server.xxx.com'
USER = 'Myuser@ftpservername'
WAIT_MILLISECONDS = 5000
LRECL = 2000
OPTIONS = '-P 2222 -i \\myserver\PrivateKey.ppk -pw "xxxxx"'
DEBUG
;
data _null_;
infile TEST;
input;
FILE 'C:\Myfile.txt' ;
put _infile_;
run;
Is this possible?
Have you already tried using 8081 in the -P option?
Yes, but then where can i provide the port number for the SFTP-server?
SFTP server use port 2222
Try this:
filename TEST SFTP '/MyFolder/'
DIR FILEEXT LSA
HOST = 'proxy.server.xxx.com'
USER = 'Myuser@ftpservername:2222'
WAIT_MILLISECONDS = 5000
LRECL = 2000
OPTIONS = '-P 8081 -i \\myserver\PrivateKey.ppk -pw "xxxxx"'
DEBUG
;
Thank you but I stil get error.
ERROR: For further debugging assistance, insert the PSFTP verbose parameters
"options='-v' debug" on the Filename sftp statement and review the SAS log.
ERROR: Time-out on sftp server response. Increasing the value of the "wait_milliseconds"
option might solve the problem.
I think it is because the password in Options is for the SFTP server and not for proxy server. Proxy server does not have a password.
WAIT_MILLISECONDS = 50000 not helping either.
adding -v on options give following error:
NOTE: psftp: Release 0.63
ERROR: Unable to launch the process; WriteFile returned rc 232 (The pipe is being closed.
).
I would tackle this from another end:
Start with getting the sftp running from the commandline; still better, start out with simple ssh
Options for ssh with a proxy are shown here:
https://stackoverflow.com/questions/19161960/connect-with-ssh-through-a-proxy
Once that works, you can use the same -o options with sftp.
Once that works, you can then use that commandline in a filename pipe to run the external command to retrieve the file to a local directory, from where you then read it.
filename sftp tends to not work with larger files over slower connections (it starts to read the file while it is still being copied, and can run into the end of the unfinished file prematurely). That's why I always call the sftp as an external command, and not with filename sftp.
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.