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
Solved

FTP  text file

Posted on 2002-05-12
7
232 Views
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!!
0
Comment
Question by:manas_ghosal
7 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 100 total points
ID: 7005368
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7005796
have a look at this complete project with source code: http://www.freevbcode.com/ShowCode.Asp?ID=1593
0
 
LVL 2

Expert Comment

by:vbDoc
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.

Regards,
vbDoc

' ******** Put in Module **********************
'
Public Const INTERNET_SERVICE_FTP = 1
Public Const FTP_TRANSFER_TYPE_BINARY = &H2
Public Const FTP_TRANSFER_TYPE_ASCII = &H1

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
  dwType = FTP_TRANSFER_TYPE_ASCII
  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
   Else
      MsgBox "Directory is changed to " & sDirectory, , "SimpleFtp"
   End If



    ' for ASCII files use FTP_TRANSFER_TYPE_ASCII
    If (FtpPutFile(hConnection, sLocalFile, sServerFile, _
     dwType, 0) = False) Then
        MsgBox "Error FtpPutFile" & Err.LastDllError
        Exit Sub
    Else
        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
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7009849
hello vbDoc. welcome to EE. take some time reading http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp because there are some rules here and one that concers the posting of answer!
0
 
LVL 1

Expert Comment

by:Moondancer
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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.
http://www.experts-exchange.com/questions/Q.11576379.html
http://www.experts-exchange.com/questions/Q.11771660.html
http://www.experts-exchange.com/questions/Q.20073130.html
http://www.experts-exchange.com/questions/Q.20074958.html
http://www.experts-exchange.com/questions/Q.20093305.html
http://www.experts-exchange.com/questions/Q.20174832.html
http://www.experts-exchange.com/questions/Q.20188009.html
http://www.experts-exchange.com/questions/Q.20257016.html
http://www.experts-exchange.com/questions/Q.20264169.html
http://www.experts-exchange.com/questions/Q.20272528.html
http://www.experts-exchange.com/questions/Q.20279237.html
http://www.experts-exchange.com/questions/Q.20287951.html
http://www.experts-exchange.com/questions/Q.20291697.html
http://www.experts-exchange.com/questions/Q.20293847.html
http://www.experts-exchange.com/questions/Q.20021632.html
http://www.experts-exchange.com/questions/Q.20021633.html
http://www.experts-exchange.com/questions/Q.20296939.html
http://www.experts-exchange.com/questions/Q.20297840.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20299864.html

*****  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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
0
 
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:
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

DO NOT ACCEPT THIS COMMENT AS AN ANSWER.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7065883
Thanks, emoreau  for your help here.

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

Moondancer - EE Moderator
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 - Compare and highlight cell not the same 3 53
SLMGR Switches Are Not Working On KMS Host 3 110
Prevent user closing word document opened with VB6 6 78
vbModal 12 57
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

860 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