How to get files from FTP Server
Hello!
I'm trying to get files from FTP server. Bellow my code:
set ftp = ##class(%Net.FtpSession).%New()
set ftp.Timeout = 5
set host="speedtest.tele2.net"
set port = 21
If 'ftp.Connect(host,"USER","USER",port) Write ftp.ReturnMessage,! Quit sc
Write "Ftp server messsage:",!,ftp.ReturnMessage,!
Set stream=##class(%GlobalCharacterStream).%New()
If 'ftp.Binary() Write "Can not swap to binary mode",! Quit sc
Write "Mode now: ",ftp.Type,!
If 'ftp.Retrieve("512KB.zip",stream) Write "Failed to get file",! Quit sc
Write "Length of file received: ",stream.Size,!
If 'ftp.Logout() Write "Failed to logout",!
Quit ftp.Logout()
I'm getting error:
Unable to open connection to speedtest.tele2.net on port 21.
I'm getting following error, running your program on Caché 2017.2.2:
USER>do ^test This FTP server is anonymous only.
And it works OK once I change Connect to be anonymous:
If 'ftp.Connect(host,"anonymous","",port) Write ftp.ReturnMessage,! Quit sc
Output:
USER>do ^test Ftp server messsage: Features: EPRT EPSV MDTM PASV REST STREAM SIZE TVFS End Mode now: Binary Length of file received: 524288
Can you connect to speedtest.tele2.net from the same server, but not from Caché? Maybe access via port 21 is blocked by your firewall?
Hello, Alexander!
I can connect to ftp://speedtest.tele2.net/ via browser.
Hello, Alexander!
I can connect to ftp://speedtest.tele2.net/ via browser.
Hello, Alexander,
is there any way in Cache to connect to ftp server using proxy?
port 21 is blocked by our firewall
Maybe your browser connects using proxy?