Shiny Language Reference
Language Reference > Web Functions
wput
bool wput(web WebVar, string URL, string Data, bool IsFile[, bool Secure, string Referrer]);
Synonyms:
bool webpost(web WebVar, string URL, string Data, bool IsFile[, bool Secure, string Referrer]);
Uses HTTP PUT to upload data to a website
The WPUT statement uses HTTP PUT to upload data to a website. Detailed discussion of the implications and configuration of a webserver to allow HTTP PUT is beyond the scope of this reference, however it does incur significant security risks. HTTP PUT is also a feature that must be specifically enabled on the webserver, so do not attempt to use this feature unless you are sure it is supported by the webserver itself.
WPUT is a "one shot" data upload. When called, any existing connections used by the variable of type WEB (parameter 1) are closed. A new connection to the target server is made and the specified data is uploaded. When the upload is complete the connection is closed again. You may not use wreadline or wreadbytes to read further data from the server - you must create a new connection with wopen to do so.
WPUT can upload a local file to the specified remote location, or can create a new file at the specified remote location and insert text into it. Refer to the Data and IsFile parameters for further information.
Note: this feature is considered experimental. Please submit bug reports and feature requests as appropriate.
Parameters
WebVar
A variable declared as type WEB, which will be temporarily allocated to the HTTP PUT connection. Once the HTTP PUT has completed (when the WPUT statement returns), this variable does not point at a valid Internet resource.
URL
A full URL to the remote file to create. For example, if you wish to write data to "myfile.txt" in the "data" folder on "www.mysite.com", this parameter would be set to "www.mysite.com/data/myfile.txt". There is no requirement to include the "http://" protocol specifier prefix.
Data
When IsFile is set to False, this parameter is a string of text to write to the remote file. When IsFile is set to True, this is the full path and filename of a file stored on a local harddrive. The file will be uploaded to the location specified in the URL parameter.
IsFile
When False, the Data parameter is treated as a string of text and written to the remote file. When True, the Data parameter is treated as the full path and filename of a file stored on a local harddrive. The file will be uploaded to the location specified in the URL parameter.
Secure
Optional. When True, Brass attempts to establish an HTTPS connection to the specified webserver. This parameter is False by default.
Referrer
Optional. A URL specifying the "fake" referrer for the URL resource in parameter 2. Many webservers will deny access to resources unless the access request has come from another resource on that same server. For example, when you browse to a webpage all the images on that page will appear, as the referrer for the resource will be the webserver itself. However if you try to directly view one of the images your access may be denied as the referrer will be incorrect. This is a standard mechanism for webservers to deny image hotlinking. By specifying a referrer in this parameter you can usually bypass such restrictions.
Return Value
TRUE if the PUT suceeded, otherwise FALSE.
Example Code
// This is fictional code to upload a sample file to a remote webserver.
// Many assumptions are made, including the remote server being able to
// accept HTTP PUT and having correct permissions.
web UploadSite;
string URL = "http://www.site.com/userfiles/myupload.txt";
string LocalFile = "C:\\MyFiles\\Personal.txt";
bool Result = wput(UploadSite, URL, LocalFile, True);