- UID
- 677066
- 积分
- 385
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2013-6-2
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 newer 于 2021-1-18 11:10 编辑
LISP下载文件方法非常多,这里仅分享四种方法;如果缺少函数请见我的其他帖子,实在找不到了在下面回帖
方法一:借助系统组件- (defun xiazai-web (url path rename /
- objHttp chrlist listi liststring
- httpstr totalstring resultstr
- value WriteBinaryStream
- )
- ;下载文件到本地(这个函数主要是替换上面的util:get_file函数的)
- ;url为可以下载的文件地址包含http
- ;path为本地路径,可以包含文件名
- ;rename为重命名的文件名,也就是说下载后对文件重命名,可以为空
- (defun WriteBinaryStream (filename data / ADOStream result xzjg)
- ; 读取远程文件 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (if (setq ADOStream (vl-catch-all-apply
- 'vlax-create-object
- (list "ADODB.Stream")
- )
- )
- (progn
- (setq result
- (vl-catch-all-apply
- (function
- (lambda ()
- (vl-catch-all-apply
- 'vlax-put-property
- (list ADOStream 'type 1)
- )
- (vl-catch-all-apply 'vlax-invoke (list ADOStream 'open))
- (vl-catch-all-apply
- 'vlax-invoke-method
- (list ADOStream 'write data)
- )
- (vl-catch-all-apply
- 'vlax-invoke
- (list ADOStream 'savetofile filename 2)
- )
- )
- )
- )
- )
- (vl-catch-all-apply
- 'vlax-invoke-method
- (list stream 'close)
- ) ;关闭文件流
- (if ADOStream
- (vlax-release-object ADOStream)
- )
- (if (not (vl-catch-all-error-p result))
- (setq xzjg filename)
- )
- )
- (if (not ADOStream)
- (if (and nil)
- (progn
- (alert "Wen10系统bug,请查看命令行,或者联系开发人员")
- (mapcar
- 'print
- (list
- "Windows Registry Editor Version 5.00" ""
- "[HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\{00000566-0000-0010-8000-00AA006D2EA4}]"
- "@=\"ADODB.Stream\"" ""
- "[HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\{00000566-0000-0010-8000-00AA006D2EA4}\\InprocServer32]"
- "@=hex(2):25,00,43,00,6f,00,6d,00,6d,00,6f,00,6e,00,50,00,72,00,6f,00,67,00,72,\\"
- " 00,61,00,6d,00,46,00,69,00,6c,00,65,00,73,00,28,00,78,00,38,00,36,00,29,00,\\"
- " 25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,5c,00,61,00,64,00,6f,00,5c,\\"
- " 00,6d,00,73,00,61,00,64,00,6f,00,31,00,35,00,2e,00,64,00,6c,00,6c,00,00,00"
- "\"ThreadingModel\"=\"Apartment\""
- "\"Assembly\"=\"ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\""
- "\"Class\"=\"ADODB.StreamClass\""
- "\"RuntimeVersion\"=\"v1.0.3705\"" ""
- "[HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\{00000566-0000-0010-8000-00AA006D2EA4}\\InprocServer32\\7.0.3300.0]"
- "\"Assembly\"=\"ADODB, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\""
- "\"Class\"=\"ADODB.StreamClass\""
- "\"RuntimeVersion\"=\"v1.0.3705\"" ""
- "[HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\{00000566-0000-0010-8000-00AA006D2EA4}\\ProgID]"
- "@=\"ADODB.Stream.6.0\"" ""
- "[HKEY_CLASSES_ROOT\\Wow6432Node\\CLSID\\{00000566-0000-0010-8000-00AA006D2EA4}\\VersionIndependentProgID]"
- "@=\"ADODB.Stream\"")
- )
- )
- (progn
- (alert
- "
- Error:
- Msado15.DLL has not started
-
- Conventional path of this file are as follows:
- \"C:\\Program Files\\Common Files\\System\\ado\\msado15.dll\"
-
- Method is to launch the system components
- regsvr32 \"C:\\Program Files\\Common Files\\System\\ado\\msado15.dll\"
- "
- )
- (IF (FINDFILE (STRCAT ""
- (getenv "systemdrive")
- "\\"
- (getenv "%zxcadazml%")
- "\\CURL"
- )
- )
- (SETENV "ZX-Download-t" "CURL")
- (exit)
- )
- )
- )
- )
- )
- xzjg
- )
- (if (and url
- (wcmatch url "http://*")
- path
- (not (and (vl-file-directory-p path) (= rename "")))
- ) ;传入进来的参数做条件判断
- (progn
- (cond
- ((and (not (vl-file-directory-p path)) (= rename ""))
- (setq rename (strcat (vl-filename-base path)
- (vl-filename-extension path)
- )
- )
- (setq path (vl-filename-directory path))
- ) ;path带有文件名,同时rename为空(重置rename 和path)
- ((and (not (vl-file-directory-p path)) (/= rename ""))
- (setq path (vl-filename-directory path)
- )
- ) ;path带有文件名,同时rename不为空(重置path)
- )
- (if (/= (substr path (- (strlen path) 2) 2) "\\")
- (setq path (strcat path "\\"))
- ) ;防止path后面没有斜杠
- (setq path (strcat path rename))
- (setq objHttp (vlax-create-object "Msxml2.XMLHTTP"))
- (vla-open objHttp
- "GET"
- url
- 0
- )
- (vlax-invoke-method objHttp "send")
- (while (/= (vlax-get-property objHttp "readyState") 4)
- (repeat 100)
- )
- (if (= (vlax-get-property objHttp "readyState") 4)
- (progn
- (setq value (vlax-get-property objHttp 'responsebody))
- (WriteBinaryStream path value)
- )
- )
- (vlax-release-object objHttp) ;释放
- )
- (progn (print "xiazai-web 函数遇到参数不足") nil)
- )
- )
方法二:借助curl
方法三:借助aria2c
- (defun $aria2c_exe远程下载$
- (WEB-f-NAME FILE-LOC lst / dd h shell str wjm xzjg zt)
- ;注意:aria2c_exe调用下载数据库文件,不需要做urlencode转码
- (setq wjm (strcat (vl-filename-base WEB-f-NAME)
- (vl-filename-extension
- WEB-f-NAME
- )
- )
- )
- (if (not (findfile "aria2c.exe"))
- (alert
- "缺少aria2c.exe程序,请联系开发人员,放到软件运行目录即可"
- )
- )
- (if (findfile "aria2c.exe")
- (setq str (strcat (findfile "aria2c.exe")
- " -d "
- (getenv "zx-hcml")
- " -o "
- wjm
- " "
- (GETENV "数据库地址")
- "/"
- (数据库支持的post方法名 "下载文件")
- WEB-f-NAME
- )
- )
- )
- (if str
- (progn (or (and lst
- (setq dd (cdr (assoc "是否等待" lst)))
- ;是否需要等待下载结束?
- (member (type dd) (list 'int))
- (or (= dd 0) (= dd 1))
- )
- (setq dd 1)
- )
- (PROGN (IF (setq Shell
- (vl-catch-all-apply
- (FUNCTION
- (LAMBDA () (vlax-create-object "wscript.shell"))
- )
- )
- )
- (PROGN
- (vl-catch-all-error-p
- (setq zt (vl-catch-all-apply
- 'vlax-invoke
- (list
- Shell 'run str 0 dd)
- )
- )
- )
- )
- )
- (and shell (vlax-release-object shell))
- )
- )
- )
- (if (= zt 0)
- (setq XZJG (findfile FILE-LOC))
- )
- XZJG
- )
- ($aria2c_exe远程下载$ web-file2 local-file nil)
方法四:借助vbs
- (defun $VBS远程下载$ (url loc lst / code *SCR DATA File L R G B)
- ;url 远程地址
- ;loc本地存储文件名,包含后缀的
- ;lst 预留
- ;注意:vbs调用下载数据库文件,不需要做urlencode转码
- (if (and url loc)
- (PROGN
- (setq url (strcat (getenv "数据库地址")
- "/"
- (数据库支持的post方法名 "下载文件")
- url
- )
- )
- (if (or (setq
- *SCR (vlax-create-object
- "Aec32BitAppServer.AecScriptControl.1"
- )
- )
- (setq *SCR (vlax-create-object "ScriptControl"))
- )
- (progn
- (vlax-put *SCR 'language "VBScript")
- (setq code
- "Function Download(url,target)
- Const adTypeBinary = 1
- Const adSaveCreateOverWrite = 2
- Dim http,ado
- Set http = CreateObject(\"Msxml2.ServerXMLHTTP\")
- http.open \"GET\",url,False
- http.send
- Set ado = createobject(\"Adodb.Stream\")
- ado.Type = adTypeBinary
- ado.Open
- ado.Write http.responseBody
- ado.SaveToFile target,2
- ado.Close
- End Function"
- )
- (if (and
- (not (vl-catch-all-error-p
- (vl-catch-all-apply
- 'vlax-invoke
- (list *SCR
- 'addcode
- code
- )
- )
- )
- )
- (not (vl-catch-all-error-p
- (setq DATA (vl-catch-all-apply
- 'vlax-invoke
- (list *SCR 'run "Download" url loc)
- )
- )
- )
- )
- (findfile loc)
- )
- ()
- (setq loc nil)
- )
- (if *SCR
- (vlax-release-object *SCR)
- )
- )
- )
- )
- )
- loc
- )
- ($VBS远程下载$ web-file2 local-file nil)
|
评分
-
查看全部评分
|