Solved

Uploading all files in a folder to ftp using VB

Posted on 2004-09-12
6
976 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

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

ie *.*
0
 
LVL 86

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

737 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