Solved

Uploading all files in a folder to ftp using VB

Posted on 2004-09-12
6
973 Views
Last Modified: 2011-10-03
I am using the code below to upload a file from within Access using the Microsoft Internet Transfer Control. Can anyone tell me how I could adjust this so that I could upload the entire contents of a folder rather than a specific file please?

Code

Function UploadFile(ByVal HostName As String, _
    ByVal UserName As String, _
    ByVal Password As String, _
    ByVal LocalFileName As String, _
    ByVal RemoteFileName As String) As Boolean

    Dim FTP As Inet

    Set FTP = New Inet
    With FTP
        .Protocol = icFTP
        .RemoteHost = HostName
        .UserName = UserName
        .Password = Password
        .Execute .URL, "Put " + LocalFileName + " " + RemoteFileName
        Do While .StillExecuting
            DoEvents
        Loop
        UploadFile = (.ResponseCode = 0)
    End With
    Set FTP = Nothing
End Function

I get the error message : Method 'Execute' of object IInet failed (at the line following Password)

I currently call it as Call UploadFile("ftp://myftp.com", "myusername", "mypassword", "Test.rtf", "Test.rtf")

Many thanks in advance
0
Comment
Question by:martmac
  • 2
  • 2
  • 2
6 Comments
 

Author Comment

by:martmac
ID: 12039112
Sorry

Text should read as below (The error messages above have now been resolved)

I am using the code below to upload a file from within Access using the Microsoft Internet Transfer Control. Can anyone tell me how I could adjust this so that I could upload the entire contents of a folder rather than a specific file please?

Code

Function UploadFile(ByVal HostName As String, _
    ByVal UserName As String, _
    ByVal Password As String, _
    ByVal LocalFileName As String, _
    ByVal RemoteFileName As String) As Boolean

    Dim FTP As Inet

    Set FTP = New Inet
    With FTP
        .Protocol = icFTP
        .RemoteHost = HostName
        .UserName = UserName
        .Password = Password
        .Execute .URL, "Put " + LocalFileName + " " + RemoteFileName
        Do While .StillExecuting
            DoEvents
        Loop
        UploadFile = (.ResponseCode = 0)
    End With
    Set FTP = Nothing
End Function

Many thanks
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 12039160
Here is one way:

Option Explicit

Private Sub Command1_Click()
    Dim files As Collection
    Dim file As Variant
   
    Set files = getFilesInDirectory("C:\Documents and Settings\Michael\My Documents\Downloads\Test1", "*")
    For Each file In files
        Call UploadFile("ftp://myftp.com", "myusername", "mypassword", file, file)
    Next file
End Sub

Private Function getFilesInDirectory(targetDirectory As String, filePattern As String) As Collection
    Dim fileCollection As Collection
    Dim curFile As String
   
    On Error GoTo noSuchDirectory
   
    Set fileCollection = New Collection
    ChDir targetDirectory
   
    On Error GoTo 0
    curFile = Dir(filePattern)
    Do Until curFile = ""
        fileCollection.Add curFile, curFile
        curFile = Dir()
    Loop
    Set getFilesInDirectory = fileCollection
    Exit Function
   
noSuchDirectory:
    MsgBox "Invalid Directory: " & targetDirectory
    Set getFilesInDirectory = fileCollection
End Function
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12039537
You may want to use mput instead of put
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 12039540
mput can specific using wild card

ie *.*
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12039629
The INET control doesn't supprot mput.

Idle_Mind
0
 

Author Comment

by:martmac
ID: 12040156
Hi EDDYKT

Thanks for this can you just explain a little further please?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question