Hi,
I have a problem with retriving a file from ftp site. From the details in log, I'm able to connect to the site and get to the target folder. However it failed to establish the connection to the file that I'd like to download. Could anyone have any ideas about this issue?
My code:
filename inv ftp 'inventory.csv'
host = 'xxxxxxxx'
user = 'xxxxxxx'
pass = 'xxxxxxxx'
port = ###
/*wait_milliseconds=1000000*/
cd = '/Download/'
recfm=s
debug;
filename lcl 'C:\Users\Downloads\inv.csv' recfm = n;
data _null_;
N=1;
infile inv NBYTE=N;
input;
file lcl;
put _infile_ @@;
run;
The log is:
NOTE: 220 (vsFTPd 3.0.2)
NOTE: <<< 220 (vsFTPd 3.0.2)
NOTE: >>> USER xxxxxx
NOTE: <<< 331 Please specify the password.
NOTE: >>> PASS XXXXXXXXXX
NOTE: <<< 230 Login successful.
NOTE: >>> OPTS UTF8 ON
NOTE: <<< 200 Always in UTF8 mode.
NOTE: >>> OPTS UTF8 NLST
NOTE: <<< 501 Option not understood.
NOTE: >>> OPTS UTF-8 NLST
NOTE: <<< 501 Option not understood.
NOTE: >>> PORT 10,16,20,27,237,200
NOTE: <<< 200 PORT command successful. Consider using PASV.
NOTE: >>> TYPE I
2 The SAS System 16:03 Friday, September 22, 2017
NOTE: <<< 200 Switching to Binary mode.
NOTE: >>> CWD /Download/
NOTE: <<< 250 Directory successfully changed.
NOTE: >>> PWD
NOTE: <<< 257 "/Download"
NOTE: >>> RETR inventory.csv
NOTE: <<< 425 Failed to establish connection.
ERROR: Invalid Reply received for the RETR command..
NOTE: UNBUFFERED is the default with RECFM=N.
Thank you in advance!
Try to use the PASSIVE option in filename ftp. This option was introduced with 9.3.
If you try to retrieve this file using the FTP command at a Windows command line then manually typing your instructions does it work OK?
I have difficulties to login the ftp site using command line. However, I can easily open the ftp site and download the file from it.
Try to use the PASSIVE option in filename ftp. This option was introduced with 9.3.
Thank you! The problem solved by adding the passvie option in filename ftp.
@Lynn_SAS wrote:
Thank you! The problem solved by adding the passvie option in filename ftp.
To further elaborate, how standard FTP works:
The client opens a connection to the server and logs in. As soon as you start a download, your client opens a port on the local computer, sends the port number to the server, and starts to listen on that port. The server now becomes "active", and tries to open a connection to your client on that port for the file transfer; basically, for this operation your client becomes a server.
Since firewalls block open ports against the outside world, this fails. When the passive option is used, all connections are made with the FTP server being the listener ("passive") and your client opening the connection to that.
Thank you again for the further explaination!
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.