NetworkRequest [examples]

The NetworkRequest class in the Lianja Framework provides support for http, https and ftp reading and writing files and other data such as making OData requests.

It supports uploading and downloading of files with (optional) authenticated requests.

It can be used by any of the supported scripting languages; Visual FoxPro, PHP, Python or JavaScript.

If the async property is set to true, then you can subclass it and define an event handler called finished(data as character) that is passed the data received or the name of the filename containing the data when the request completes. If async is false then the operation is performed synchronously.

When using it in async mode the progressChanged(currentvalue as numeric, totalsize as numeric) event handler is called allowing you to provide progress feedback to the user during the request.

Additionally, in async mode you can call oRequest.isFinished() to determine if the request has completed.

You can verify that you have a valid network connections using oRequest.networkAccessible() and check for errors using oRequest.errorNumber and oRequest.errorString

oRequest = createObject("networkrequest")
oRequest.async = .f.
oRequest.username = "yourname"
oRequest.password = "yourpassword"
oRequest.setHeader("name", "value")
oRequest.setHeader("name2", "value")
oRequest.getFile("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.getFile("https://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.getFile("ftp://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.putFile("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.putFile("https://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.putFile("ftp://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.postFile("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.postFile("https://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.postFile("ftp://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
m_string = oRequest.getData("http://www.anywhere.com/filename.xxx?arg=value&arg2=value")
oRequest.putData("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", "send this to the server")
oRequest.postData("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", "send this to the server")

You can use this class very effectively when working with OData services in the Cloud.

https://www.lianja.com/doc/index.php/Web_Integration


 

NetworkRequest

Q:

what’s the best way to send a file with FTP?

A:

If you are in production you should be using ftps or sftp, in which case the Chilkat Extensions (FTP, which includes FTPS, and SFTP) are what we use.

Unprotected FTP servers will be probed within 30 seconds of being put up, from what I’ve seen on our servers.

If you need a protected FTP Server, you can monkey around with IIS and waste many hours, or you can get Cerberus, which is easy to use and just keeps working.

the Chilkat Extensions are from chilkatsoft.com, by subscription. They are available (for one price) for just about every platform. In addition to the FTP/S and SFTP controls, we use their email, zip, and http and Crypt controls. The http control is used from our VFP-based app to hit a Lianja web service, for example.

You can find “free” versions of controls that do most of the same stuff. The difference is in having control of all the features you need to match what your customers are using, and in the fantastic support (as good as Barry’s, almost as fast <s>). Also, many of the common usages have been “conceptualized” into an easy-to-use command that makes complex tasks easy. I’ve saved a couple of projects and hundreds of hours since I started using them for, I think, the past 10 years or so.

In one case we needed FTPS before it was common (we were working with a casino, with enhanced security needs). I wrote Matt at Chlkat explaining our need. He said if I’d set up a server he’d write it. We did, and he did, just like that.


 

 

NetworkRequest

Q:

Code:
oRequest.putFile("ftp://www.timelinecontinuum.com/9-11.xml?username='myUserName'&password='myPassword' ",xmlName)

A:
You can however only use http:// or https:// not ftp:// with “NetworkRequest”
If you want to upload using sftp i would recommend that you look at using the chilkat components for Lianja from http://www.chilkatsoft.com/lianja.asp


Q:
I would like to have the targetFile and source file both coming from variables.
It works Ok with source file as xmlName where xmlName contains something like “C:\Lianja\Data\timeline\9-11.XML”.
But targetFile resists my attempts to use a variable. I would like to pass through a file name and a subdirectory on my Host.
So TargetFile would be something like “/DataXML/filename.xml”.
A:
You can substitute variables into strings using &varname. which would let you use variables. Otherwise you can just create the character variable and use that as an argument to the method call.
Try omitting the / from the start of the target file. Does that directory already exist and if so does it have the correct permissions.
it may be that the target can only be a filename.
One solution would be to have a username that when logged in uses a different directory on the ftp server but that would require some configuration and is Server dependent.