FTP  text file

Posted on 2002-05-12
Last Modified: 2010-05-02
Can any body please tell me how to  VB program that would let me FTP a text file to an ftp server on a daily basis??
Its very urgent!!
Question by:manas_ghosal

Accepted Solution

xSinbad earned 100 total points
ID: 7005368
LVL 70

Expert Comment

by:Éric Moreau
ID: 7005796
have a look at this complete project with source code:

Expert Comment

ID: 7009587
Hi manas_ghosal,
Here is some code that will FTP a file. You will need to write code to fire the SUB at the time that you need. I tested it. Any Questions, just let me know.


' ******** Put in Module **********************

Public hOpen As Long, hConnection As Long, hFile As Long
Public dwType As Long
Public dwSeman As Long

Public 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

Public 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

Public 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

Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Long

Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
    (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean

Sub Command1_Click()
' **************************Button on form ***********************
' When clicked it will
'     1. open a connection
'     2. Change the directory.
'     3. Transfer the file.
'     4. Close the connection.
' Slap some timer type of code to fire this sub and you will
' be all set.
' ****************************************************************

    Dim sServer As String
    Dim sUser As String
    Dim sPW As String
    Dim sLocalFile As String
    Dim sServerFile As String
    Dim sDirectory As String
    sServer = "Hot Stuff"              ' put server name here
    sUser = "Hot1"                     ' put user name here
    sPW = "4B3a7"                      ' Put Password here
    sLocalFile = "c:\junk\testftp.txt" ' Put path and name of local file here
    sServerFile = "testftp.txt"        ' put name of server file here (normaly the same)
    sDirectory = "httpdocs"            ' put directory name/path to change here
  hOpen = InternetOpen("My VB Test", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  If hOpen = 0 Then
    MsgBox Err.LastDllError & " InternetOpen"
    Unload Form1
  End If
  dwSeman = 0
  hConnection = 0
    If hConnection <> 0 Then
        InternetCloseHandle hConnection
    End If '»If hConnection <> 0 Then

    hConnection = InternetConnect(hOpen, sServer, INTERNET_INVALID_PORT_NUMBER, _
    sUser, sPW, INTERNET_SERVICE_FTP, dwSeman, 0)

   If (FtpSetCurrentDirectory(hConnection, sDirectory) = False) Then
      MsgBox Err.LastDllError & "FtpSetCurrentDirectory"
      Exit Sub
      MsgBox "Directory is changed to " & sDirectory, , "SimpleFtp"
   End If

    If (FtpPutFile(hConnection, sLocalFile, sServerFile, _
     dwType, 0) = False) Then
        MsgBox "Error FtpPutFile" & Err.LastDllError
        Exit Sub
        MsgBox "File transfered!", , "Simple Ftp"
    End If

    ' Close Connection
    If hConnection <> 0 Then
        InternetCloseHandle hConnection
    End If '»If hConnection <> 0 Then
    hConnection = 0
    MsgBox "Disconnected.", , "SimpleFtp"

end sub
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 70

Expert Comment

by:Éric Moreau
ID: 7009849
hello vbDoc. welcome to EE. take some time reading because there are some rules here and one that concers the posting of answer!

Expert Comment

ID: 7011576
You logged in as recently as May 13, 2002 and we have asked that you finalize your open questions in April of this year.  Some of your open questions date back to the year 2000, and must be finalized.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link 
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
LVL 70

Expert Comment

by:Éric Moreau
ID: 7060682
This question appears to be abandoned. A question regarding it will be left in the Community Support
area; if you have any comment about the question, please leave it here.

Unless there is objection or further activity, one of the moderators will be asked to accept the comment
of <xSinbad >.

The link to the Community Support area is:


Expert Comment

ID: 7065883
Thanks, emoreau  for your help here.

I have finalized this question, and will monitor it for comments.

Moondancer - EE Moderator

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question ( 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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 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