ba5tz

Upload FTP

Oct 22nd, 2020 (edited)
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.89 KB | None | 0 0
  1. Private Const FTP_TRANSFER_TYPE_UNKNOWN     As Long = 0
  2. Private Const INTERNET_FLAG_RELOAD          As Long = &H80000000
  3.  
  4. Private Declare Function InternetOpenA Lib "wininet.dll" ( _
  5.     ByVal sAgent As String, _
  6.     ByVal lAccessType As Long, _
  7.     ByVal sProxyName As String, _
  8.     ByVal sProxyBypass As String, _
  9.     ByVal lFlags As Long) As Long
  10.  
  11. Private Declare Function InternetConnectA Lib "wininet.dll" ( _
  12.     ByVal hInternetSession As Long, _
  13.     ByVal sServerName As String, _
  14.     ByVal nServerPort As Long, _
  15.     ByVal sUsername As String, _
  16.     ByVal sPassword As String, _
  17.     ByVal lService As Long, _
  18.     ByVal lFlags As Long, _
  19.     ByVal lcontext As Long) As Long
  20.  
  21. Private Declare Function FtpPutFileA _
  22.    Lib "wininet.dll" _
  23.  _
  24.        (ByVal hFtpSession As Long, _
  25.         ByVal lpszLocalFile As String, _
  26.         ByVal lpszRemoteFile As String, _
  27.         ByVal dwFlags As Long, _
  28.         ByVal dwContext As Long) As Boolean
  29.  
  30. Private Declare Function InternetCloseHandle Lib "wininet" ( _
  31.     ByVal hInet As Long) As Long
  32.  
  33. Sub FtpUpload(ByVal strLocalFile As String, ByVal strRemoteFile As String, ByVal strHost As String, ByVal lngPort As Long, ByVal strUser As String, ByVal strPass As String)
  34.     Dim hOpen   As Long
  35.     Dim hConn   As Long
  36.  
  37.     hOpen = InternetOpenA("FTPGET", 1, vbNullString, vbNullString, 1)
  38.     hConn = InternetConnectA(hOpen, strHost, lngPort, strUser, strPass, 1, 0, 2)
  39.  
  40.     If FtpPutFileA(hConn, strLocalFile, strRemoteFile, FTP_TRANSFER_TYPE_UNKNOWN Or INTERNET_FLAG_RELOAD, 0) Then
  41.         Debug.Print "Success"
  42.     Else
  43.         Debug.Print "Fail"
  44.     End If
  45.  
  46.     'Close connections
  47.     InternetCloseHandle hConn
  48.     InternetCloseHandle hOpen
  49.  
  50. End Sub
  51.  
  52. 'Pengunaaan
  53. '--------------------
  54. Sub TestUpload
  55. FtpUpload "C:\text file.txt", "//Download/text file.txt", _
  56.             "192.168.0.100", 21, "username", "password"
  57. End Sub
Add Comment
Please, Sign In to add comment