Advertisement
rakanturki12222

FTP AUTOIT

Jun 10th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.10 KB | None | 0 0
  1. ;===============================================================================
  2. ;
  3. ; Function Name:    _FTPOpen()
  4. ; Description:      Opens an FTP session.
  5. ; Parameter(s):     $s_Agent        - Random name. ( like "myftp" )
  6. ;                   $l_AccessType   - I dont got a clue what this does.
  7. ;                   $s_ProxyName    - ProxyName.
  8. ;                   $s_ProxyBypass  - ProxyByPasses's.
  9. ;                   $l_Flags        - Special flags.
  10. ; Requirement(s):   DllCall, wininet.dll
  11. ; Return Value(s):  On Success - Returns an indentifier.
  12. ;                   On Failure - 0  and sets @ERROR
  13. ; Author(s):        Wouter van Kesteren.
  14. ;
  15. ;===============================================================================
  16.  
  17. Func _FTPOpen($s_Agent, $l_AccessType = 1, $s_ProxyName = '', $s_ProxyBypass = '', $l_Flags = 0)
  18.    
  19.     Local $ai_InternetOpen = DllCall('wininet.dll', 'long', 'InternetOpen', 'str', $s_Agent, 'long', $l_AccessType, 'str', $s_ProxyName, 'str', $s_ProxyBypass, 'long', $l_Flags)
  20.     If @error OR $ai_InternetOpen[0] = 0 Then
  21.         SetError(-1)
  22.         Return 0
  23.     EndIf
  24.        
  25.     Return $ai_InternetOpen[0]
  26.    
  27. EndFunc ;==> _FTPOpen()
  28.  
  29. ;===============================================================================
  30. ;
  31. ; Function Name:    _FTPConnect()
  32. ; Description:      Connects to an FTP server.
  33. ; Parameter(s):     $l_InternetSession  - The Long from _FTPOpen()
  34. ;                   $s_ServerName       - Server name/ip.
  35. ;                   $s_Username         - Username.
  36. ;                   $s_Password         - Password.
  37. ;                   $i_ServerPort       - Server port ( 0 is default (21) )
  38. ;                   $l_Service          - I dont got a clue what this does.
  39. ;                   $l_Flags            - Special flags.
  40. ;                   $l_Context          - I dont got a clue what this does.
  41. ; Requirement(s):   DllCall, wininet.dll
  42. ; Return Value(s):  On Success - Returns an indentifier.
  43. ;                   On Failure - 0  and sets @ERROR
  44. ; Author(s):        Wouter van Kesteren
  45. ;
  46. ;===============================================================================
  47.  
  48. Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0)
  49.    
  50.     Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context)
  51.     If @error OR $ai_InternetConnect[0] = 0 Then
  52.         SetError(-1)
  53.         Return 0
  54.     EndIf
  55.            
  56.     Return $ai_InternetConnect[0]
  57.    
  58. EndFunc ;==> _FTPConnect()
  59.  
  60. ;===============================================================================
  61. ;
  62. ; Function Name:    _FTPPutFile()
  63. ; Description:      Puts an file on an FTP server.
  64. ; Parameter(s):     $l_FTPSession   - The Long from _FTPConnect()
  65. ;                   $s_LocalFile    - The local file.
  66. ;                   $s_RemoteFile   - The remote Location for the file.
  67. ;                   $l_Flags        - Special flags.
  68. ;                   $l_Context      - I dont got a clue what this does.
  69. ; Requirement(s):   DllCall, wininet.dll
  70. ; Return Value(s):  On Success - 1
  71. ;                   On Failure - 0
  72. ; Author(s):        Wouter van Kesteren
  73. ;
  74. ;===============================================================================
  75.  
  76. Func _FTPPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0)
  77.  
  78.     Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context)
  79.     If @error OR $ai_FTPPutFile[0] = 0 Then
  80.         SetError(-1)
  81.         Return 0
  82.     EndIf
  83.    
  84.     Return $ai_FTPPutFile[0]
  85.    
  86. EndFunc ;==> _FTPPutFile()
  87.  
  88. ;===============================================================================
  89. ;
  90. ; Function Name:    _FTPDelFile()
  91. ; Description:      Delete an file from an FTP server.
  92. ; Parameter(s):     $l_FTPSession   - The Long from _FTPConnect()
  93. ;                   $s_RemoteFile   - The remote Location for the file.
  94. ; Requirement(s):   DllCall, wininet.dll
  95. ; Return Value(s):  On Success - 1
  96. ;                   On Failure - 0
  97. ; Author(s):        Wouter van Kesteren
  98. ;
  99. ;===============================================================================
  100.  
  101. Func _FTPDelFile($l_FTPSession, $s_RemoteFile)
  102.    
  103.     Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpDeleteFile', 'long', $l_FTPSession, 'str', $s_RemoteFile)
  104.     If @error OR $ai_FTPPutFile[0] = 0 Then
  105.         SetError(-1)
  106.         Return 0
  107.     EndIf
  108.    
  109.     Return $ai_FTPPutFile[0]
  110.    
  111. EndFunc ;==> _FTPDelFile()
  112.  
  113. ;===============================================================================
  114. ;
  115. ; Function Name:    _FTPRenameFile()
  116. ; Description:      Renames an file on an FTP server.
  117. ; Parameter(s):     $l_FTPSession   - The Long from _FTPConnect()
  118. ;                   $s_Existing     - The old file name.
  119. ;                   $s_New          - The new file name.
  120. ; Requirement(s):   DllCall, wininet.dll
  121. ; Return Value(s):  On Success - 1
  122. ;                   On Failure - 0
  123. ; Author(s):        Wouter van Kesteren
  124. ;
  125. ;===============================================================================
  126.  
  127. Func _FTPRenameFile($l_FTPSession, $s_Existing, $s_New)
  128.    
  129.     Local $ai_FTPRenameFile = DllCall('wininet.dll', 'int', 'FtpRenameFile', 'long', $l_FTPSession, 'str', $s_Existing, 'str', $s_New)
  130.     If @error OR $ai_FTPRenameFile[0] = 0 Then
  131.         SetError(-1)
  132.         Return 0
  133.     EndIf
  134.    
  135.     Return $ai_FTPRenameFile[0]
  136.    
  137. EndFunc ;==> _FTPRenameFile()
  138.  
  139. ;===============================================================================
  140. ;
  141. ; Function Name:    _FTPMakeDir()
  142. ; Description:      Makes an Directory on an FTP server.
  143. ; Parameter(s):     $l_FTPSession   - The Long from _FTPConnect()
  144. ;                   $s_Remote       - The file name to be deleted.
  145. ; Requirement(s):   DllCall, wininet.dll
  146. ; Return Value(s):  On Success - 1
  147. ;                   On Failure - 0
  148. ; Author(s):        Wouter van Kesteren
  149. ;
  150. ;===============================================================================
  151.  
  152. Func _FTPMakeDir($l_FTPSession, $s_Remote)
  153.    
  154.     Local $ai_FTPMakeDir = DllCall('wininet.dll', 'int', 'FtpCreateDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
  155.     If @error OR $ai_FTPMakeDir[0] = 0 Then
  156.         SetError(-1)
  157.         Return 0
  158.     EndIf
  159.    
  160.     Return $ai_FTPMakeDir[0]
  161.    
  162. EndFunc ;==> _FTPMakeDir()
  163.  
  164. ;===============================================================================
  165. ;
  166. ; Function Name:    _FTPDelDir()
  167. ; Description:      Delete's an Directory on an FTP server.
  168. ; Parameter(s):     $l_FTPSession   - The Long from _FTPConnect()
  169. ;                   $s_Remote       - The Directory to be deleted.
  170. ; Requirement(s):   DllCall, wininet.dll
  171. ; Return Value(s):  On Success - 1
  172. ;                   On Failure - 0
  173. ; Author(s):        Wouter van Kesteren
  174. ;
  175. ;===============================================================================
  176.  
  177. Func _FTPDelDir($l_FTPSession, $s_Remote)
  178.    
  179.     Local $ai_FTPDelDir = DllCall('wininet.dll', 'int', 'FtpRemoveDirectory', 'long', $l_FTPSession, 'str', $s_Remote)
  180.     If @error OR $ai_FTPDelDir[0] = 0 Then
  181.         SetError(-1)
  182.         Return 0
  183.     EndIf
  184.        
  185.     Return $ai_FTPDelDir[0]
  186.    
  187. EndFunc ;==> _FTPDelDir()
  188.  
  189. ;===============================================================================
  190. ;
  191. ; Function Name:    _FTPClose()
  192. ; Description:      Closes the _FTPOpen session.
  193. ; Parameter(s):     $l_InternetSession  - The Long from _FTPOpen()
  194. ; Requirement(s):   DllCall, wininet.dll
  195. ; Return Value(s):  On Success - 1
  196. ;                   On Failure - 0
  197. ; Author(s):        Wouter van Kesteren
  198. ;
  199. ;===============================================================================
  200.  
  201. Func _FTPClose($l_InternetSession)
  202.    
  203.     Local $ai_InternetCloseHandle = DllCall('wininet.dll', 'int', 'InternetCloseHandle', 'long', $l_InternetSession)
  204.     If @error OR $ai_InternetCloseHandle[0] = 0 Then
  205.         SetError(-1)
  206.         Return 0
  207.     EndIf
  208.    
  209.     Return $ai_InternetCloseHandle[0]
  210.    
  211. EndFunc ;==> _FTPClose()
  212.  
  213.  
  214. $server = 'ftp.example.com'
  215. $username = 'secretusers'
  216. $pass = 'hiddenpass'
  217.  
  218. $Open = _FTPOpen('MyFTP Control')
  219. $Conn = _FTPConnect($Open, $server, $username, $pass)
  220. $Ftpp = _FtpPutFile($Conn, 'C:\WINDOWS\Notepad.exe', '/somedir/Example.exe')
  221. $Ftpc = _FTPClose($Open)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement