ilrosebud26
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are the best! This worked great.
lngINetConn = InternetConnect(lngINet, "ftp.mysite.com", 0 <--- Maybe this should be set to 21 for typical ftp port