Link to home
Start Free TrialLog in
Avatar of ilrosebud26
ilrosebud26Flag for United States of America

asked on

Put csv file on ftp server using vba from excel

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

ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

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
Avatar of ilrosebud26

ASKER

You are the best!  This worked great.