Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FTP  text file

Posted on 2002-05-12
7
Medium Priority
?
237 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
[X]
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
7 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses

688 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