6 Replies - 12241 Views - Last Post: 09 June 2012 - 12:05 PM

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Upload file to FTP server - VB6

Posted 14 February 2009 - 10:57 PM

Description: Paste the first 4 lines at the top of your module. Provide server name, port, username, password, local file name and the file you want it named to the procedure UploadFileThis is a snippet that allows you to upload a file to an FTP server using Win32 API's
'Paste at the top of your code file
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Const INTERNET_SERVICE_FTP = 1


'Upload method
Public Sub UploadFile(ByRef server As String, ByRef username As String, ByRef password As String, ByRef port As Integer, ByRef localFileName As String, ByRef remoteFileName As String)
    Dim session As Long
    Dim connection As Long
    
    On Error GoTo UploadError
    
    Set session = InternetOpen("MyApplication", 0, vbNullString, vbNullString, 0)
    Set connection = InternetConnect(session, server, port, username, password, INTERNET_SERVICE_FTP, 0, 0)
    
    If FtpPutFile(connection, localFileName, remoteFileName, False, 1, 0) = False Then
        MsgBox "File: " & localFileName & " uploaded successfully!"
    Else
        MsgBox "ERROR: " & Err.Description
    End If
UploadError:
    MsgBox Err.Description
 End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Upload file to FTP server - VB6

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Upload file to FTP server - VB6

Posted 14 February 2009 - 10:57 PM

Description: Paste the first 4 functions at the top of your module. Provide server name, port, username, password, local file name and the file you want it named to the procedure UploadFileThis is a snippet that allows you to upload a file to an FTP server using Win32 API's
'Paste at the top of your code file
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, _
ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, _
ByVal lContext As Long) As Long

Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean

Private Const INTERNET_SERVICE_FTP = 1


'Upload method
Public Sub UploadFile(ByRef server As String, ByRef username As String, ByRef password As String, _
ByRef port As Integer, ByRef localFileName As String, ByRef remoteFileName As String)
    Dim session As Long
    Dim connection As Long
    
    On Error GoTo UploadError
    
    Set session = InternetOpen("MyApplication", 0, vbNullString, vbNullString, 0)
    Set connection = InternetConnect(session, server, port, username, password, INTERNET_SERVICE_FTP, 0, 0)
    
    If FtpPutFile(connection, localFileName, remoteFileName, False, 1, 0) = False Then
        MsgBox "File: " & localFileName & " uploaded successfully!"
    Else
        MsgBox "ERROR: " & Err.Description
    End If
UploadError:
    MsgBox Err.Description
 End Sub

Was This Post Helpful? 0
  • +
  • -

#3 sramu   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-February 09

Re: Upload file to FTP server - VB6

Posted 16 February 2009 - 02:00 AM

this is not working
Was This Post Helpful? 0
  • +
  • -

#4 andreneo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 30-April 09

Re: Upload file to FTP server - VB6

Posted 30 April 2009 - 07:40 PM

this just got my hopes up, it doesn't WORK
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Upload file to FTP server - VB6

Posted 01 May 2009 - 06:57 AM

Dd you change "MyApplication in this line? Set session = InternetOpen("MyApplication", 0, vbNullString, vbNullString, 0)
Was This Post Helpful? 0
  • +
  • -

#6 brtaiwo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-September 10

Re: Upload file to FTP server - VB6

Posted 30 September 2010 - 10:15 AM

It is not working. What am I missing?
Was This Post Helpful? 0
  • +
  • -

#7 mukek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 03-February 12

Re: Upload file to FTP server - VB6

Posted 03 February 2012 - 08:16 AM

got error in [Set session = InternetOpen("MyApplication", 0, vbNullString, vbNullString, 0)] ...and [Set connection = InternetConnect(session, server, port, username, password, INTERNET_SERVICE_FTP, 0, 0)] just remove 'set' and change lAccessType to 1 correct is.... session = InternetOpen("MyApplication", 1, vbNullString, vbNullString, 0) connection = InternetConnect(session, server, port, username, password, INTERNET_SERVICE_FTP, 0, 0) and also got error in [If FtpPutFile(connection, localFileName, remoteFileName, False, 1, 0) = False Then] should change it to.. If FtpPutFile(connection, localFileName, remoteFileName, FTP_TRANSFER_TYPE_BINARY,0) <> False Then ....and declare FTP_TRANSFER_TYPE_BINARY = &H1 so lastly call it... Private Sub Command1_Click() UploadFile "ftp.drivehq.com", "user", "pass1234", 21, "c:\test.txt", "test.txt" End Sub problem fixed...
Was This Post Helpful? 0
  • +
  • -

#8 evry1falls   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 25-April 12

Re: Upload file to FTP server - VB6

Posted 09 June 2012 - 12:05 PM

check this out : http://evry1falls.fr...B6/ftpfull.html
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1