Solved

Put csv file on ftp server using vba from excel

Posted on 2008-06-17
3
574 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ return type for nested group query 6 74
vb6 programatically bring window to front 8 65
VB 6.0 printer how to align 6 58
using Access 8 59
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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now