We help IT Professionals succeed at work.


Does anybody know of any good vb ftp code sites. Im having real trouble with the upload / download code. I've managed to establish the connection, but thats about it. If any of you know the code, then i'll increase the points.
Watch Question

Visit www.vbip.com.
There is a very good FTP source code prg available.
I have three suggestions;

sells such programs, allows free trials, and has good documentation,
get their examples and study them

go to a linux site and find a ftp tutorial

go to an appropiate site and get the rfc's on ftp

Go to www.mvps.org and then select almost any of the participating sites. Run a search for "FTP" on Karl Peterson's or Randy Birch's site (to name just two) and you'll get a ton of results complete with source for building FTP servers and clients.


I've now managed to get the connection and the download part working, but the bit im having trouble with is the upload. The code in the module for download is as follows:

Public Declare Function FtpGetFile Lib "Wininet.dll" _
   Alias "FtpGetFileA" _
  (ByVal hConnect As Long, _
   ByVal lpszRemoteFile As String, _
   ByVal lpszNewFile As String, _
   ByVal fFailIfExists As Long, _
   ByVal dwFlagsAndAttributes As Long, _
   ByVal dwFlags As Long, _
   ByVal dwContext As Long) As Long

and the code for the actual download is as follows:

'download the file
      If FtpGetFile(hConnect, _
                    sRemoteFile, _
                    sNewFile, _
                    False, _
                    FILE_ATTRIBUTE_ARCHIVE, _
                    FTP_TRANSFER_TYPE_UNKNOWN, _
                    0&) Then
        'show the success message
         Label1.Caption = sFile & " has been downloaded to " & sNewFile
        'show any error
         Label1.Caption = GetErr(Err.LastDllError)
      End If  'If FtpGetFile

Any ideas as to what i'd need to do for the upload?


P.S If I can get this working, i'll increase the points to 150.


I've now increased the points. I've found some code that supposedly uploads. The following goes in a module:

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


How do I get it to work?
I created a class.. so the Me.Whatever's are references to class members.. ignore them, as the function works with the optional variables as well...

Oh yeah.. the ReportError is also a custom built function.. you can use whatever you want.

Hope this helps

Public Function Upload(Optional szLocalFile As String, Optional szRemoteFile As String) As Boolean
On Error GoTo Err_Upload

    ' assume success
    Upload = True
    If Trim(szLocalFile) <> "" Then
        Me.LocalFile = szLocalFile
    End If
    If Trim(szRemoteFile) <> "" Then
        Me.RemoteFile = szRemoteFile
    End If
    If Me.LocalFile = "" Then
        Upload = False
        ReportError 201, "Local file not specified", "Upload"
    End If
    If Upload = True Then
        If Me.RemoteFile = "" Then
            Dim dwPosition As Long
            dwPosition = InStrRev(Me.LocalFile, "\")
            ' get the resulting file name
            Me.RemoteFile = Mid(Me.LocalFile, dwPosition + 1)
        End If
        If FtpPutFile(Me.ConnectionHandle, Me.LocalFile, Me.RemoteFile, mdwTransferType, 0) = False Then
            Upload = False
            ReportError Err.LastDllError, "File not uploaded", "Upload"
        End If
    End If

    Exit Function
    Upload = False
    ReportError Err.Number, Err.Description, "Upload"
End Function
Author of the Year 2009

Hi vibale,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept sridhar_PJ's comment(s) as an answer.

vibale, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
Per recommendation, force-accepted.

CS Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.