Upload file to web using LISP
Hello,
I am trying to build an online licensing mechanism for use in AutoCAD/Bricscad and want to know if it is possible using Lisp fucnctions (calling ActiveX, or Windows system calls or whatever) to upload a file to a web-site.
For example, if I have created a file called LICENSE.TXT, and I want to upload the same to http://www.coordsys.com, can I do it completely using Lisp?
Of course, I would need a username and password to connect to my web-site. That can be provided into the Lisp program.
What I am looking for (or dreaming about) is the opposite of the GetRemote utility which can pull a file off a web folder and read it into CAD.
Regards
Rakesh
Comments
-
Hi Rahesh,
Try that:
[code](setq file (open "ftpfile.txt" "w"))
(write-line "domain" file)
(write-line "password" file)
(write-line "cd //" file)
(write-line "cd domains/domain.com/public_html/folder" file)
(write-line (strcat "put " filename-to-sent) file)
(close file)
(dos_exewait (strcat "ftp -s:" "\"" "ftpfile.txt" "\"" " www.domain.com" ))[/code]
Regards, Vaidas0 -
0
-
Thanks, Vaidas,
Did you try that code? Does it work?
I discovered just now that there indeed is a PutRemoteFile method also available in the Utility collection of the drawing document. But, the downside as it appears to be is that the username and password must be supplied on a popu dialog box. I want it to be hidden and supplied internally by the program. need to check a little more. Perhaps, there is a solution somehow.
Regards
Rakesh
http://rakeshrao.typepad.com0 -
I'm using this code for my own needs. Add [code](write-line "binary" file)[/code] line before "put" if you need to sent executable.
Regards, Vaidas0 -
Now that lisp can send/retrieve data from .NET, you can use the framework to create your password dialog and manage your internet connection.. just a thought
0 -
Now that lisp can send/retrieve data from .NET, you can use the framework to create your password dialog and manage your internet connection.. just a thought
I think Rakesh Rao wants to create a fully automated ftp upload mechanism without any dialogs or other user interaction. But I would love to see a sample of using the .net framework in lisp...0 -
-
[code]
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Net;
//alias
using _AcRx = Teigha.Runtime;
using _AcBrx = Bricscad.Runtime;
using _AcAp = Bricscad.ApplicationServices;
using _AcDb = Teigha.DatabaseServices;
[assembly: _AcRx.CommandClass(typeof(BcadMgdTest.Commands))]
namespace BcadMgdTest
{
public static class Commands
{
static FtpStatusCode putFile(string url, string username,
string password, string file)
{
FtpStatusCode code = FtpStatusCode.Undefined;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
StreamReader sourceStream = new StreamReader(file);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
code = response.StatusCode;
response.Close();
return code;
}
static string getWebPage(string url)
{
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[4096];
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
resStream.Close();
response.Close();
return sb.ToString();
}
//(getWebPage "http://www.cadext.com/downloads/4334.txt")
[_AcRx.LispFunction("getWebPage")]
public static object getWebPage(_AcDb.ResultBuffer args)
{
try
{
if (args != null)
{
List<<span style="color: #010001;">_AcDb.TypedValue> list =
new List<<span style="color: #010001;">_AcDb.TypedValue>(args.AsArray());
if (list.Count != 0 && list[0].TypeCode ==
(int)_AcBrx.LispDataType.Text)
{
return getWebPage((string)list[0].Value);
}
}
}
catch (System.Exception ex)
{
_AcAp.Application.ShowAlertDialog(ex.Message + ex.StackTrace);
}
return null;
}
//(putFile "ftp://ftp.cadext.com/downloads/4334.txt" "username" "passwd" "c:/4334.txt")
[_AcRx.LispFunction("putFile")]
public static object putFile(_AcDb.ResultBuffer args)
{
try
{
if (args != null)
{
List<<span style="color: #010001;">_AcDb.TypedValue> list =
new List<<span style="color: #010001;">_AcDb.TypedValue>(args.AsArray());
if (list.Count != 4)
return null;
foreach (_AcDb.TypedValue T in list)
{
if (T.TypeCode != (int)_AcBrx.LispDataType.Text)
return null;
}
return putFile(
(string)list[0].Value,
(string)list[1].Value,
(string)list[2].Value,
(string)list[3].Value).ToString();
}
}
catch (System.Exception ex)
{
_AcAp.Application.ShowAlertDialog(ex.Message + ex.StackTrace);
}
return null;
}
}
}
[/code]
Capture.PNG0 -
@Daniel:
I'm sorry for any confusion but actually I was thinking of using Lisp's com-capabilities to call .Net Framework components. This may not be possible however. My search has turned up web pages that discuss the possibility of creating com links to .Net-based programs, but I have not found any info about directly linking to the .NET redistributable.
[code]
;;; Which library to import?:
(vlax-import-type-library
:tlb-filename "C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\mscorlib.tlb"
:methods-prefix "mscm-"
:properties-prefix "mscp-"
:constants-prefix "mscc-"
)
;;; A lot of functions but what to do with them?:
(setq funcsNames (vl-sort (vl-remove-if-not '(lambda (a) (wcmatch a "MSC?-*")) (atoms-family 1)) '<))<br>
;;; What is the main object in the object model?:
(setq sys (vlax-create-object "System.Object"))
[/code]0 -
FTP can be accomplished in LISP via a very simple (one line) script, I have accomplished this earlier. BUT it is my opinion that you choose a different language/method as the security aspect is nearly non-existent with a pure LISP FTP implementation.0
-
Hi Rakesh,
what about making a call via a web browser? something in the form of:
[code](startapp "explorer" "http://www.mysite.com/myproduct/?myuniquecode12345678")[/code]
or
[code](startapp "explorer" (strcat (chr 34) "http://maps.google.com/maps?q=C-616,+Natasha+Golf+View,+Domlur+Layout,+Bangalore,+india" (chr 34)))[/code]
Regards,Jason Bourhill
0 -
@Vaidas Guogis: I can get as far as logging in to the site, changing directories and all that but the PUT statement does not work. It seems to give the error : 500 Illegal port range rejected.Do you know why? How to solve this error?I did run up searches of the web but did not get a clear solution. They say "set it to passive mode", but I am already in passive mode. That is what 'quote PASV does.This is how my FTP script now looks like, if anyone wants to comment and suggest a fix.The test I am doing is simple. Just trying to copy a text file BCAD.TXT residing in F:/ to the public_html/sanjith/ims folder.//// Startopen addr.com
username
password
quote PASV
type ascii
cd public_html
cd sanjith
cd ims
delete bcad.txt
put f:/bcad.txt bcad.txt
disconnect
quit////// EndSorry, Rakesh0 -
0
-
You are most likely receiving a port error as you are attempting to upload to FTP but you are using a standard HTTP port. Try to change the line referencing addr.com to ftp.addr.com and see what that does for you...0