Solved

Ftp a file using VBA

Posted on 2004-09-11
6
897 Views
Last Modified: 2010-05-02
I am trying to upload a file from within Access using the Microsoft Internet Transfer Control

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 call it as Call UploadFile("ftp://myftp.com", "myusername", "mypassword", "Test.rtf", "Test.rtf")

Where am I going wrong?????

Many thanks in advance

 
0
Comment
Question by:martmac
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 12036955
I tested your code and only had one problem.  That was creating an instance of the Inet control.  I commented out these two lines

    Dim FTP As Inet
    Set FTP = New Inet

replacing then with an instance of the inet control on the form.  I named the control FTP so the rest of your code could remain the same.  I then called your function and uploaded a file to my FTP site without a problem.
0
 
LVL 20

Expert Comment

by:dsacker
ID: 12036957
Separate your URL and Execute statements (or if your .RemoteHost identifies where you're FTP'ing to, you probably don't even need the URL):

    With FTP
        .Protocol = icFTP
        .RemoteHost = HostName    <-- use either this
        .URL = HostName        <-- or this, but not both
        .UserName = UserName
        .Password = Password
        .Execute , "SEND " + LocalFileName + " " + RemoteFileName   <-- SEND is usually the standard for Inet
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 12036963
Oh, one other thought.  You shouldn't prefix the address of your ftp site with ftp://.  When I try adding that onto the address I used I get an error too, although not the same one you got.  The error I got was "Unable to connect to remote host".
0
Industry Leaders: 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!

 

Author Comment

by:martmac
ID: 12037628
Many thanks BlueDevilFan , that did the trick
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12039554
No problem.  Glad I could help.
0
 

Expert Comment

by:eguether
ID: 13941051
Hi, BlueDevilFan and dsacker.  I'm having the same problem.  Working in Excel 2003.

I tried both of your suggestions.  But the macro fails at the function's ".Protocol = icFTP" file.  Run-time error '424'.

BlueDevilFan mentioned (1) commenting out Dim FTP As Inet and  Set FTP = New Inet and (2) replacing them with an instance of the inet control on the form.  [he named the control FTP so the rest of the code could remain the same.]  BlueDevilFan, how did you replace that with an instance of the inet control?  

Any help would be appreciated.

Eric
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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

685 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