관리 메뉴

ㄴrㅎnㅂrㄹrㄱi

DllCall: Basic FTP Functions 본문

AUTOHOTKEY/스크립트

DllCall: Basic FTP Functions

님투 2007. 10. 29. 00:13
반응형

  1. /*
  2. http://msdn.microsoft.com/library/en-us/wininet/wininet/ftp_sessions.asp
  3. http://msdn.microsoft.com/library/en-us/wininet/wininet/internetopen.asp
  4. http://msdn.microsoft.com/library/en-us/wininet/wininet/internetconnect.asp
  5. */
  6.  
  7. FtpCreateDirectory(DirName) {
  8. global ic_hInternet
  9. r := DllCall("wininetFtpCreateDirectoryA", "uint", ic_hInternet, "str", DirName)
  10. If (ErrorLevel != 0 or r = 0)
  11. return 0
  12. else
  13. return 1
  14. }
  15.  
  16. FtpRemoveDirectory(DirName) {
  17. global ic_hInternet
  18. r := DllCall("wininetFtpRemoveDirectoryA", "uint", ic_hInternet, "str", DirName)
  19. If (ErrorLevel != 0 or r = 0)
  20. return 0
  21. else
  22. return 1
  23. }
  24.  
  25. FtpSetCurrentDirectory(DirName) {
  26. global ic_hInternet
  27. r := DllCall("wininetFtpSetCurrentDirectoryA", "uint", ic_hInternet, "str", DirName)
  28. If (ErrorLevel != 0 or r = 0)
  29. return 0
  30. else
  31. return 1
  32. }
  33.  
  34. FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) {
  35. ;Flags:
  36. ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
  37. ;FTP_TRANSFER_TYPE_ASCII = 1
  38. ;FTP_TRANSFER_TYPE_BINARY = 2
  39. If NewRemoteFile=
  40. NewRemoteFile := LocalFile
  41. global ic_hInternet
  42. r := DllCall("wininetFtpPutFileA"
  43. , "uint", ic_hInternet
  44. , "str", LocalFile
  45. , "str", NewRemoteFile
  46. , "uint", Flags
  47. , "uint", 0) ;dwContext
  48. If (ErrorLevel != 0 or r = 0)
  49. return 0
  50. else
  51. return 1
  52. }
  53.  
  54. FtpGetFile(RemoteFile, NewFile="", Flags=0) {
  55. ;Flags:
  56. ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
  57. ;FTP_TRANSFER_TYPE_ASCII = 1
  58. ;FTP_TRANSFER_TYPE_BINARY = 2
  59. If NewFile=
  60. NewFile := RemoteFile
  61. global ic_hInternet
  62. r := DllCall("wininetFtpGetFileA"
  63. , "uint", ic_hInternet
  64. , "str", RemoteFile
  65. , "str", NewFile
  66. , "int", 1 ;do not overwrite existing files
  67. , "uint", 0 ;dwFlagsAndAttributes
  68. , "uint", Flags
  69. , "uint", 0) ;dwContext
  70. If (ErrorLevel != 0 or r = 0)
  71. return 0
  72. else
  73. return 1
  74. }
  75.  
  76. FtpGetFileSize(FileName, Flags=0) {
  77. ;Flags:
  78. ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY)
  79. ;FTP_TRANSFER_TYPE_ASCII = 1
  80. ;FTP_TRANSFER_TYPE_BINARY = 2
  81. global ic_hInternet
  82. fof_hInternet := DllCall("wininetFtpOpenFileA"
  83. , "uint", ic_hInternet
  84. , "str", FileName
  85. , "uint", 0x80000000 ;dwAccess: GENERIC_READ
  86. , "uint", Flags
  87. , "uint", 0) ;dwContext
  88. If (ErrorLevel != 0 or fof_hInternet = 0)
  89. return -1
  90.  
  91. FileSize := DllCall("wininetFtpGetFileSize", "uint", fof_hInternet, "uint", 0)
  92. DllCall("wininetInternetCloseHandle",  "UInt", fof_hInternet)
  93. return, FileSize
  94. }
  95.  
  96.  
  97. FtpDeleteFile(FileName) {
  98. global ic_hInternet
  99. r :=  DllCall("wininetFtpDeleteFileA", "uint", ic_hInternet, "str", FileName)
  100. If (ErrorLevel != 0 or r = 0)
  101. return 0
  102. else
  103. return 1
  104. }
  105.  
  106. FtpRenameFile(Existing, New) {
  107. global ic_hInternet
  108. r := DllCall("wininetFtpRenameFileA", "uint", ic_hInternet, "str", Existing, "str", New)
  109. If (ErrorLevel != 0 or r = 0)
  110. return 0
  111. else
  112. return 1
  113. }
  114.  
  115. FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="") {
  116. IfEqual, Username, 0, SetEnv, Username, anonymous
  117. IfEqual, Password, 0, SetEnv, Password, anonymous
  118.  
  119. If (Proxy != "")
  120. AccessType=3
  121. Else
  122. AccessType=1
  123. ;#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
  124. ;#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
  125. ;#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
  126. ;#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS
  127.  
  128. global ic_hInternet, io_hInternet
  129. hModule := DllCall("LoadLibrary", "str", "wininet.dll")
  130.  
  131. io_hInternet := DllCall("wininetInternetOpenA"
  132. , "str", A_ScriptName ;lpszAgent
  133. , "UInt", AccessType
  134. , "str", Proxy
  135. , "str", ProxyBypass
  136. , "UInt", 0) ;dwFlags
  137.  
  138. If (ErrorLevel != 0 or io_hInternet = 0) {
  139. FtpClose()
  140. return 0
  141. }
  142.  
  143. ic_hInternet := DllCall("wininetInternetConnectA"
  144. , "uint", io_hInternet
  145. , "str", Server
  146. , "uint", Port
  147. , "str", Username
  148. , "str", Password
  149. , "uint" , 1 ;dwService (INTERNET_SERVICE_FTP = 1)
  150. , "uint", 0 ;dwFlags
  151. , "uint", 0) ;dwContext
  152.  
  153. If (ErrorLevel != 0 or ic_hInternet = 0)
  154. return 0
  155. else
  156. return 1
  157. }
  158.  
  159. FtpClose() {
  160. global ic_hInternet, io_hInternet
  161. DllCall("wininetInternetCloseHandle",  "UInt", ic_hInternet)
  162. DllCall("wininetInternetCloseHandle",  "UInt", io_hInternet)
  163. DllCall("FreeLibrary", "UInt", hModule)
  164. }
  165.  

 

  1. ; sample values
  2. FtpHost = autohotkey.net
  3. FtpPort = 21
  4. FtpUsername = AhkH4x0r
  5. FtpPassword = Ahk1337
  6. localFile = C:FtpTest.txt
  7. remoteFile = test/FtpTest.txt
  8.  
  9. ; establish connection to FTP server
  10. connect:
  11.    FtpConnection := FtpOpen(FtpHost, FtpPort, FtpUsername, FtpPassword)
  12.    If (FtpConnection != 1)
  13.    {
  14.       MsgBox, Error connecting to FTP server.
  15.       GoSub, quit
  16.    }
  17. Return
  18.  
  19. ; upload file
  20. uploadFile:
  21.     ; establish connection to FTP server
  22.    GoSub, connect
  23.    ; store file on FTP server
  24.    fileTransfer := FtpPutFile(localFile, remoteFile)
  25.    If (fileTransfer != 1)
  26.    {
  27.       MsgBox, Error uploading file.
  28.       GoSub, quit
  29.    }
  30.    ; close connection
  31.    FtpClose()
  32.    ; confirmation message
  33.    MsgBox, Upload complete.
  34.    ; terminate script
  35.    GoSub, quit
  36. Return
  37.  
  38. ; download file
  39. downloadFile:
  40.     ; establish connection to FTP server
  41.    GoSub, connect
  42.    ; retrieve file from FTP server
  43.    fileTransfer := FtpGetFile(remoteFile, localFile)
  44.    If (fileTransfer != 1)
  45.    {
  46.       MsgBox, Error downloading file.
  47.       GoSub, quit
  48.    }
  49.    ; close connection
  50.    FtpClose()
  51.    ; confirmation message
  52.    MsgBox, Download complete.
  53.    ; terminate script
  54.    GoSub, quit
  55. Return

 

  1. ; ----------------------------------------------
  2. ; ----------------------------------------------
  3. Txt2Hex(Txt) { ;v1.0 by Elevator_Hazard
  4. format := A_FormatInteger
  5. StringSplit, TxtArray, Txt
  6. loop, %TxtArray0%
  7.   {
  8.   CurrentTxt := TxtArray%A_Index%
  9.   blah := Asc(CurrentTxt)
  10.   SetFormat, Integer, Hex
  11.   Hex := Asc(CurrentTxt)
  12.   SetFormat, Integer, Decimal
  13.   StringReplace, Hex, Hex, 0x,,All
  14.   If StrLen(Hex) = 1
  15.     {
  16.     Hex := Hex . "0"
  17.     }
  18.   Hex%A_Index% := Hex
  19.   }
  20. Hex=
  21. Loop, %TxtArray0%
  22.   {
  23.   Hex := Hex . Hex%A_Index%
  24.   }
  25. SetFormat, Integer, %Format%
  26. return %Hex%
  27. }
  28.  
  29. Hex2Txt(Hex) { ;v1.0 by Elevator_Hazard
  30. format := A_FormatInteger
  31. go=1
  32. Txt=
  33. HexLen := StrLen(Hex)
  34. Loop, %HexLen%
  35.   {
  36.   If go=1
  37.   {
  38.   go=0
  39.   HexSet := "0x" . SubStr(Hex, A_Index, 2)
  40.   SetFormat, Integer, Decimal
  41.   HexSet += 0
  42.   Txt := Txt . Chr(HexSet)
  43.   }
  44.   else
  45.   {
  46.   go=1
  47.   }
  48.   }
  49. SetFormat, Integer, %Format%
  50. return %Txt%
  51. }

 

  1. ; ########################
  2. ; ##### Auto-Exec ########
  3. ; ########################
  4. URL=http://clangs.org/index.php?showtopic=1373
  5. version=1.0
  6. URLDownloadToFile, http://www.autohotkey.net/~Elevator_Hazard/HexiWizardUpdate.txt, %A_WorkingDir%CheckForUpdates.txt
  7. FileReadLine, URLVersion, %A_WorkingDir%CheckForUpdates.txt, 1
  8. If URLVersion=%version%
  9. {
  10. }
  11. Else
  12. {
  13. FileRead, UpdateInfo, %A_WorkingDir%CheckForUpdates.txt
  14. Gosub, UpdateWin
  15. }
  16.  
  17. IniRead, HasBeenUsed, %A_WorkingDir%Config.ini, general, hasbeenused
  18. if HasBeenUsed = 1
  19. {
  20.  
  21. }
  22. else
  23. {
  24. IniWrite, 1, %A_WorkingDir%Config.ini, general, hasbeenused
  25. MsgBox, HexiWizard is now running`, To capture a pixels color under the mouse`,press Ctrl+Shift+/`,`n to choose a custom color`, press the "Choose Color" Button.
  26. }
  27. mini           = 0
  28. SLIDE_DUR      = 750
  29. FADE_DUR       = 1000
  30. sampint= 0
  31. title  = HexiWizard
  32. FADE_IN            = 0xa0000
  33. FADE_OUT           = 0x90000
  34. ROLL_TOP_TO_BOTTOM = 0x20004
  35. ROLL_BOTTOM_TO_TOP = 0x20008
  36. SLIDE_TOP_TO_BOTTOM= 0x40004
  37. SLIDE_BOTTOM_TO_TOP= 0x40008
  38.  
  39. ;GUI_HEIGHT    = 351
  40. GUI_HEIGHT    = 380
  41. GUI_WIDTH     = 294
  42. GUI_START_X  := A_ScreenWidth  - GUI_Width
  43. GUI_START_Y  := A_ScreenHeight - GUI_Height
  44. GUI_MINI_Y   := A_ScreenHeight - 50
  45. gui, +Toolwindow -Caption +Border +LastFound +AlwaysOnTop
  46. gui, add, text, gMini vMiniText x264 y3 w17 h17 +Center +Border, __
  47. gui, add, text, gExit x279 y3 w17 h17 +Center +Border, X
  48. Gui, Add, GroupBox, x16 y10 w230 h80 +Center, Choose Color
  49. Gui, Add, Button, x76 y40 w100 h30 gChooseColor, Choose Color
  50. Gui, Add, GroupBox, x16 y90 w230 h80 +Center, Regular Hex Code
  51. Gui, Add, Edit, x86 y140 w90 h20 ReadOnly vRegHex,
  52. Gui, Add, GroupBox, x16 y170 w230 h80 +Center, HTML Hex Code
  53. Gui, Add, Edit, x86 y220 w90 h20 ReadOnly vHTMLHex,
  54. Gui, Add, GroupBox, x16 y250 w230 h80 +Center, Warcraft 3 Hex Code
  55. Gui, Add, Edit, x86 y300 w90 h20 ReadOnly vWc3Hex,
  56. Gui, Add, Progress, x256 y20 w30 h310 vSampColor c%Color%, 100
  57. ;Gui, Add, Picture, x256 y20 w30 h310 vSampColor ,%A_WorkingDir%Color.bmp
  58. ; Generated using SmartGUI Creator 4.0
  59. hWnd := WinExist()
  60. Gui, Show, x%GUI_START_X% y%GUI_START_Y% h%GUI_HEIGHT% w%GUI_WIDTH% Hide, %title%
  61. AnimateWindow(hWnd,SLIDE_DUR,SLIDE_BOTTOM_TO_TOP)
  62. Return
  63.  
  64. ; ########################
  65. ; ##### Subroutines ######
  66. ; ########################
  67.  
  68. URL:
  69. run, %URL%
  70. return
  71.  
  72. 2GuiClose:
  73. Gui, 2: destroy
  74. return
  75.  
  76. UpdateWin:
  77. Gui,2: +AlwaysOnTop
  78. Gui,2: Add, Text, x153 y10 w90 h20 , Update Available!
  79. Gui,2: Add, GroupBox, x16 y30 w360 h310 ,
  80. Gui,2: Add, Text, x26 y50 w340 h280 , %UpdateInfo%
  81. Gui,2: Add, GroupBox, x16 y340 w360 h90 ,
  82. Gui,2: Add, Text, x26 y350 w330 h20 , The Newest Version of this program is available at:
  83. Gui,2: Add, Text, x36 y380 w330 h20 gURL +Border c0000ff Underline, %URL%
  84. ; Generated using SmartGUI Creator 4.0
  85. Gui,2: Show, x431 y292 h455 w399, Update!
  86. return
  87.  
  88. ^+?::
  89. Color := MouseGetColor()
  90. gosub, SetColors
  91. return
  92.  
  93. ChooseColor:
  94. Color := ChooseColor()
  95. gosub, SetColors
  96. return
  97.  
  98. SetColors:
  99. SampInt++
  100. StringRight,MouseColor,MouseColor,6
  101.  
  102. guicontrol,hide,sampcolor
  103. Gui, Add, Progress, x256 y20 w30 h310 vSampColor%SampInt% c%Color%, 100
  104.  
  105. guicontrol,,RegHex,%Color%
  106. guicontrol,,HTMLHex,#%Color%
  107. guicontrol,,Wc3Hex,|cff%Color%
  108. return
  109.  
  110. GuiClose:
  111. Exit:
  112. AnimateWindow(hWnd,FADE_DUR,FADE_OUT)
  113. ExitApp
  114.  
  115. Mini:
  116. If mini=1
  117. {
  118. Gui,  +AlwaysOnTop
  119. mini=0
  120. GuiControl,,MiniText,__
  121. WinMove, %title%,, %GUI_START_X%, %GUI_START_Y%
  122. Gui, hide
  123. AnimateWindow(hWnd,SLIDE_DUR,SLIDE_BOTTOM_TO_TOP)
  124. }
  125. else
  126. {
  127. Gui, -AlwaysOnTop
  128. mini=1
  129. GuiControl,,MiniText,^
  130. WinMove, %title%,, %GUI_START_X%, %GUI_MINI_Y%
  131. }
  132. return
  133.  
  134. ; ########################
  135. ; ##### Functions ########
  136. ; ########################
  137.  
  138. ;---AnimateWindow---
  139. AnimateWindow(hWnd,Duration,Flag) {
  140. Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
  141. }
  142.  
  143. ;---MouseGetColor---
  144. MouseGetColor() {
  145. MouseGetPos,x,y
  146. PixelGetColor,c,x,y,RGB
  147. return %c%
  148. }
  149.  
  150. ;---ChooseColor---
  151. ChooseColor( Color=0x0, hPar=0x0, ccFile="")  {
  152. Color := SubStr(Color,1,2)="0x" ? Color : "0x" Color      ; Check & Prefix Color with "0x"
  153. VarSetCapacity(CHOOSECOLOR, 36, 0) , mainPtr := (&CHOOSECOLOR)     ; Create Main structure
  154. DllCall( "RtlFillMemory", UInt,mainPtr+0, Int,1, UChar,36 ) ; Insert size of the Structure
  155.  
  156. hPar := WinExist(ahk_id %hPar%) ; Validate the passed Parent window ID
  157. ; Break Parent window ID into 4 bytes
  158. H1 := hPar>>0 & 255,   H2 := hPar>>8 & 255,   H3 := hPar>>16 & 255,   H4 := hPar>>24 & 255
  159. Loop 4                       ; Insert Parent window ID to CHOOSECOLOR structure @ Offset 4
  160.   DllCall( "RtlFillMemory", UInt,mainPtr+3+A_Index, Int,1, UChar,H%A_Index% )
  161.  
  162. ; Break Color into R,G and B values
  163. RGB1 := Color>>16 & 255,    RGB2 := Color>>8  & 255,    RGB3 := Color>>0  & 255
  164. Loop 3                      ; Insert R,G and B values to CHOOSECOLOR structure @ Offset 12
  165.   DllCall( "RtlFillMemory", UInt,mainPtr+11+A_Index, Int,1, UChar,RGB%A_Index% )
  166.  
  167. ; CustomColors ( CUS1 will be primary array and CUS2 will be a copy to detect any change )
  168. VarSetCapacity(CUS1, 64, 0),   aPtr := (&CUS1),   VarSetCapacity(CUS2, 64, 0)
  169. IfEqual,ccFile,, SetEnv,ccFile,%A_WinDir%CUSTOMCOLOR.BIN ; Assign default save filename
  170. IfExist,%ccFile%,  FileRead,CUS1, *m64 %ccFile%           ; Array CUS1 will be overwritten
  171. Loop 64                                                   ; Copy data from CUS1 to CUS2
  172. oS:=A_Index-1, DllCall( "RtlFillMemory", UInt,&CUS2+oS, Int,1, UChar,*(&CUS1+oS) )
  173. A1 := aPtr>>0 & 255,   A2 := aPtr>>8 & 255,   A3 := aPtr>>16 & 255,   A4 := aPtr>>24 & 255
  174. Loop 4        ; Insert pointer to Custom colors array to CHOOSECOLOR structure @ Offset 16
  175.    DllCall( "RtlFillMemory", UInt,mainPtr+15+A_Index, Int,1, UChar,A%A_Index% )
  176.  
  177. ; Insert Integer 259 @ Offset 21 (259 is CC_RGBINIT + CC_FULLOPEN + CC_ANYCOLOR )
  178. DllCall( "RtlFillMemory", UInt,mainPtr+20, Int,1,UChar,3  ) ; CC_RGBINIT=1 + CC_FULLOPEN=2
  179. DllCall( "RtlFillMemory", UInt,mainPtr+21, Int,1,UChar,1  ) ; CC_ANYCOLOR=256
  180.  
  181. If ! DllCall("comdlg32ChooseColorA", str, CHOOSECOLOR) OR errorLevel   ; Call ChooseColor
  182.      Return -1            ; and return -1 in case of an error or if no color was selected.
  183.  
  184. Loop 64 ; Compare data CUS2 and CUS1, if custom color changed, then save array to BIN file
  185.   If ( *(&CUS1+A_Index-1) != *(&CUS2+A_Index-1) )   {       ; Check byte by byte
  186.        h := DllCall( "_lcreat", Str,ccFile, Int,0 )         ; Overwrite/create file
  187.             DllCall( "_lwrite", UInt,h, Str,CUS1, Int,64 )  ; write the array,
  188.             DllCall( "_lclose", UInt,h )                    ; close the file,
  189.             Break                                           ; break the loop.
  190.                                                     }
  191. Hex := "123456789ABCDEF0",   RGB := mainPtr+11
  192. Loop 3 ; Extract nibbles directly from main structure and convert it into Hex (initd. abv)
  193.   HexColorCode .=  SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
  194. Return HexColorCode ; finally ... phew!
  195. }

 

 

 

반응형
Comments