Solved

Put csv file on ftp server using vba from excel

Posted on 2008-06-17
3
578 Views
Last Modified: 2012-08-13
I have a csv file which I have created that I need to transfer to an ftp server that is hosted.  I have opened up other questions trying to get this answer but I guess I am not explaning myself well....and I am new at this.  The file is called costing.csv and it is located on my local drive in the my documents folder.  I am trying to transfer to the ftp server in a folder named test/incoming.  I have found some code on the site which looks like it would accomplish what I need to do but it is not working. Is there somewhere that I can find examples of this?  What does sAgent mean? I would appreciate any help that could be given.  I am assigning higher points to this because I am desperate for help!
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
    (ByVal sAgent As String, ByVal lAccessType As Long, _
     ByVal sProxyName As String, _
     ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
 
Private Declare Function InternetConnect Lib "wininet.dll" Alias _
    "InternetConnectA" _
    (ByVal hInternetSession As Long, ByVal sServerName As String, _
     ByVal nServerPort As Integer, ByVal sUsername As String, _
     ByVal sPassword As String, ByVal lService As Long, _
     ByVal lFlags As Long, ByVal lContext As Long) As Long
 
Private Declare Function FtpPutFile Lib "wininet.dll" Alias _
    "FtpPutFileA" _
    (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
    ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _
    ByVal dwContext As Long) As Boolean
 
Sub FTPUpload()
Dim lngINet
Dim lngINetConn
Dim blnRC
 
lngINet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)
lngINetConn = InternetConnect(lngINet, "ftp.mysite.com", 0, _
    "ID", "PASSWORD", 1, 0, 0)
blnRC = FtpPutFile(lngINetConn, "C:\my documents\Costing.csv", "/TEST/incoming/Costing.csv", 1, 0)
End Sub

Open in new window

0
Comment
Question by:ilrosebud26
[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
3 Comments
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 21806837
You have to make sure you close the handle when your finished
Option Explicit
 
Private Declare Function InternetOpenA Lib "wininet.dll" ( _
    ByVal sAgent As String, _
    ByVal lAccessType As Long, _
    ByVal sProxyName As String, _
    ByVal sProxyBypass As String, _
    ByVal lFlags As Long) As Long
 
Private Declare Function InternetConnectA Lib "wininet.dll" ( _
    ByVal hInternetSession As Long, _
    ByVal sServerName As String, _
    ByVal nServerPort As Long, _
    ByVal sUsername As String, _
    ByVal sPassword As String, _
    ByVal lService As Long, _
    ByVal lFlags As Long, _
    ByVal lcontext As Long) As Long
 
Private Declare Function FtpPutFileA Lib "wininet.dll" ( _
    ByVal hConnect As Long, _
    ByVal lpszLocalFile As String, _
    ByVal lpszNewRemoteFile As String, _
    ByVal dwFlags As Long, _
    ByVal dwContext As Long) As Boolean
 
Private Declare Function InternetCloseHandle Lib "wininet" ( _
    ByRef hInet As Long) As Long
    
Sub Upload(ByVal remFile As String, ByVal locFile As String, ByVal Host As String, User As String, Pass As String, ByVal Port As Long)
    Dim hOpen   As Long
    Dim hConn   As Long
    hOpen = InternetOpenA("FTP", 1, vbNullString, vbNullString, 1)
    hConn = InternetConnectA(hOpen, Host, Port, User, Pass, 1, 0, 2)
    FtpPutFileA hConn, locFile, remFile, 0, 0
    InternetCloseHandle hConn
    InternetCloseHandle hOpen
End Sub

Open in new window

0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 21806874
The error I belive in your code would be

lngINetConn = InternetConnect(lngINet, "ftp.mysite.com", 0 <--- Maybe this should be set to 21 for typical ftp port
0
 

Author Closing Comment

by:ilrosebud26
ID: 31468108
You are the best!  This worked great.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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 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…

730 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