Solved

Ftp a file using VBA

Posted on 2004-09-11
6
886 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

26 Experts available now in Live!

Get 1:1 Help Now