Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Upload a file. Return True if we are successful.
  2. Private Function UploadFile(ByVal source_file As String, _
  3.     ByVal dest_file As String, ByVal host_name As String, _
  4.     ByVal user_name As String, ByVal passwd As String) As _
  5.     Boolean
  6.     ' Get the file's contents.
  7.    On Error GoTo UploadError
  8.  
  9.     ' You must set the URL before the user name and
  10.    ' password. Otherwise the control cannot verify
  11.    ' the user name and password and you get the error:
  12.    '
  13.    '       Unable to connect to remote host
  14.    If LCase$(Left$(host_name, 6)) <> "ftp://" Then _
  15.         host_name = "ftp://" & host_name
  16.     inetFtp.URL = host_name
  17.     inetFtp.UserName = user_name
  18.     inetFtp.Password = passwd
  19.  
  20.     ' Do not include the host name here. That will make
  21.    ' the control try to use its default user name and
  22.    ' password and you'll get the error again.
  23.    inetFtp.Execute , "Put " & source_file & " " & dest_file
  24.  
  25.     UploadFile = True
  26.     Exit Function
  27.  
  28. UploadError:
  29.     MsgBox "Error " & Err.Number & _
  30.         " uploading file '" & _
  31.         source_file & "' to '" & _
  32.         dest_file & "'." & vbCrLf & Err.Description, _
  33.         vbExclamation Or vbOKOnly, _
  34.         "Download Error"
  35.     UploadFile = False
  36.     Exit Function
  37. End Function
  38.  
  39.  
  40. ' Upload the file.
  41. Private Sub cmdUploadFile_Click()
  42.     Screen.MousePointer = vbHourglass
  43.     DoEvents
  44.  
  45.     If UploadFile(txtFromFile.Text, txtToFile.Text, _
  46.         txtHostName.Text, txtUserName.Text, _
  47.         txtPassword.Text) Then
  48.         MsgBox "Upload Complete", _
  49.             vbOKOnly Or vbInformation, _
  50.             "Done"
  51.     End If
  52.  
  53.     Screen.MousePointer = vbDefault
  54. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement