Solved

Ftp a file using VBA

Posted on 2004-09-11
6
894 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

773 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