#NoEnv ;首先你要在ftp创建upload文件夹 FileInstall, ftp_upload.exe, ftp_upload.exe Gui, add, edit, x0 y0 w300 h20 vpath, Gui, Add, Button, x300 y0 w100 h20 gsfile, 浏览 Gui, add, edit, x0 y20 w300 h20 vdpath, Gui, Add, Button, x300 y20 w100 h20 gupload, 上传获取URL gui, show, , Nano云文件外链(FTP上传) ;定义你的ftp用户名密码 result := FtpOpen("ftp.nanoyun.com",,"xxxxx/xxxxxcdn","xxxxxxxpass") if result = 0 { MsgBox, 4112, 错误, 无法连接到服务器 ExitApp } return sfile: FileSelectFile, path, , , 选择要上传的文件, (*jpg;*.png;*.gif;*.zip;*.rar;*.zip;*.7z;*.ahk;*.aau;*.exe) ;允许上传的文件类型 if path { IfNotInString, path, %A_Space% GuiControl, , path, % path else { FileCopy, % path, % npath := RegExReplace(path," ","_") GuiControl, , path, % npath } GuiControl, , dpath, } return upload: Gui, Submit, NoHide if path { FileDelete, result.txt SplitPath, path, , , ext md5 := FileMD5(path) /* 外部工具方案 RunWait, % ComSpec " /c ftp_upload.exe ftp.nanoyun.com user pass " path " /upload/" md5 "." ext " >result.txt", , Hide FileRead, result, result.txt if result MsgBox, 64, 提示, % result */ result := FtpPutFile(path, "/upload/" md5 "." ext, 2) if result = 0 { MsgBox, 4112, 错误, 上传遇到错误! return } MsgBox, 64, 提示, % result "`n已复制到剪切板!" GuiControl, , dpath, % Clipboard := "http://cdn.ywwx.com.cn/upload/" md5 "." ext ;此处是你的外链网址 需要修改 } return GuiClose: FtpClose() ExitApp ;ftp函数集 FtpCreateDirectory(DirName) { ;创建目录 global ic_hInternet r := DllCall("wininet\FtpCreateDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpRemoveDirectory(DirName) { ;移除目录 global ic_hInternet r := DllCall("wininet\FtpRemoveDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpSetCurrentDirectory(DirName) { ;设置当前目录 global ic_hInternet r := DllCall("wininet\FtpSetCurrentDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) { ;上传文件 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 文本方式 ;FTP_TRANSFER_TYPE_BINARY = 2 二进制方式 If NewRemoteFile= NewRemoteFile := LocalFile global ic_hInternet r := DllCall("wininet\FtpPutFileA" , "uint", ic_hInternet , "str", LocalFile , "str", NewRemoteFile , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpGetFile(RemoteFile, NewFile="", Flags=0) { ;下载文件 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 ;FTP_TRANSFER_TYPE_BINARY = 2 If NewFile= NewFile := RemoteFile global ic_hInternet r := DllCall("wininet\FtpGetFileA" , "uint", ic_hInternet , "str", RemoteFile , "str", NewFile , "int", 1 ;do not overwrite existing files , "uint", 0 ;dwFlagsAndAttributes , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpGetFileSize(FileName, Flags=0) { ;获取文件大小 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 ;FTP_TRANSFER_TYPE_BINARY = 2 global ic_hInternet fof_hInternet := DllCall("wininet\FtpOpenFileA" , "uint", ic_hInternet , "str", FileName , "uint", 0x80000000 ;dwAccess: GENERIC_READ , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or fof_hInternet = 0) return -1 FileSize := DllCall("wininet\FtpGetFileSize", "uint", fof_hInternet, "uint", 0) DllCall("wininet\InternetCloseHandle", "UInt", fof_hInternet) return, FileSize } FtpDeleteFile(FileName) { ;删除文件 global ic_hInternet r := DllCall("wininet\FtpDeleteFileA", "uint", ic_hInternet, "str", FileName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpRenameFile(Existing, New) { ;重命名文件 global ic_hInternet r := DllCall("wininet\FtpRenameFileA", "uint", ic_hInternet, "str", Existing, "str", New) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="") { ;打开ftp连接 IfEqual, Username, 0, SetEnv, Username, anonymous IfEqual, Password, 0, SetEnv, Password, anonymous If (Proxy != "") AccessType=3 Else AccessType=1 ;#define INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration ;#define INTERNET_OPEN_TYPE_DIRECT 1 // direct to net ;#define INTERNET_OPEN_TYPE_PROXY 3 // via named proxy ;#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS global ic_hInternet, io_hInternet, hModule hModule := DllCall("LoadLibrary", "str", "wininet.dll") io_hInternet := DllCall("wininet\InternetOpenA" , "str", A_ScriptName ;lpszAgent , "UInt", AccessType , "str", Proxy , "str", ProxyBypass , "UInt", 0) ;dwFlags If (ErrorLevel != 0 or io_hInternet = 0) { FtpClose() return 0 } ic_hInternet := DllCall("wininet\InternetConnectA" , "uint", io_hInternet , "str", Server , "uint", Port , "str", Username , "str", Password , "uint" , 1 ;dwService (INTERNET_SERVICE_FTP = 1) , "uint", 0 ;dwFlags , "uint", 0) ;dwContext If (ErrorLevel != 0 or ic_hInternet = 0) return 0 else return 1 } FtpClose() { ;关闭ftp连接 global ic_hInternet, io_hInternet, hModule DllCall("wininet\InternetCloseHandle", "UInt", ic_hInternet) DllCall("wininet\InternetCloseHandle", "UInt", io_hInternet) DllCall("FreeLibrary", "UInt", hModule) } FileMD5(filename) ;计算文件MD5值 { return CalcFileHash(filename, 0x8003, 64 * 1024) } CalcFileHash(filename, algid, continue = 0, byref hash = 0, byref hashlength = 0) ;计算文件hash { fpos := "" if (!(f := FileOpen(filename, "r"))) { return } f.pos := 0 if (!continue && f.length > 0x7fffffff) { return } if (!continue) { VarSetCapacity(data, f.length, 0) f.rawRead(&data, f.length) f.pos := oldpos return CalcAddrHash(&data, f.length, algid, hash, hashlength) } hashlength := 0 while (f.pos < f.length) { readlength := (f.length - fpos > continue) ? continue : f.length - f.pos VarSetCapacity(data, hashlength + readlength, 0) DllCall("RtlMoveMemory", "Ptr", &data, "Ptr", &hash, "Ptr", hashlength) f.rawRead(&data + hashlength, readlength) h := CalcAddrHash(&data, hashlength + readlength, algid, hash, hashlength) } return h } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"] static b := h.minIndex() hProv := hHash := o := "" if (DllCall("advapi32\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "UInt", 24, "UInt", 0xf0000000)) { if (DllCall("advapi32\CryptCreateHash", "Ptr", hProv, "UInt", algid, "UInt", 0, "UInt", 0, "Ptr*", hHash)) { if (DllCall("advapi32\CryptHashData", "Ptr", hHash, "Ptr", addr, "UInt", length, "UInt", 0)) { if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", 0, "UInt*", hashlength, "UInt", 0)) { VarSetCapacity(hash, hashlength, 0) if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", &hash, "UInt*", hashlength, "UInt", 0)) { loop % hashlength { v := NumGet(hash, A_Index - 1, "UChar") o .= h[(v >> 4) + b] h[(v & 0xf) + b] } } } } DllCall("advapi32\CryptDestroyHash", "Ptr", hHash) } DllCall("advapi32\CryptReleaseContext", "Ptr", hProv, "UInt", 0) } return o }
49 queries in 1.978 seconds |