[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Ftp a file using VBA

Posted on 2004-09-11
6
Medium Priority
?
916 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 1500 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
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!

 

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

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.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

872 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