Solved

FTP  text file

Posted on 2002-05-12
7
229 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
Comment Utility
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
Thanks, emoreau  for your help here.

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

Moondancer - EE Moderator
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

11 Experts available now in Live!

Get 1:1 Help Now