Solved

Uploading all files in a folder to ftp using VB

Posted on 2004-09-12
6
971 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 39
Microsoft Access combo box help 2 44
using web browser with BING 40 118
Send outlook email from VBS Script 2 28
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now