Results 1 to 2 of 2

Thread: FTP a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    12

    Arrow

    I wonder if someone could help me by giving me the code to do the following:

    I got txtHost, txtUser and txtPass. Also, I got the full
    path to a file in txtPath.Text (i.e. "c:\file.txt") plus
    the Winsock control placed on the form.

    Now, I need the code to upload the file from txtPath.Text
    to the FTP server found in txtHost.Text with the username
    and password from txtUser.Text and txtPass.Text. Using the
    Winsock control.

    How do I do that?
    I hope someone can get back to me as soon as possible.

    Thanks in advance,
    Fredrik - [email protected]

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122
    Hi,

    has it to be WINSOCK? Here's a solution with WININET.DLL:

    Declarations:

    Code:
    Private Const INTERNET_OPEN_TYPE_PROXY = 3
    Private Const INTERNET_INVALID_PORT_NUMBER = 0
    Public Const INTERNET_SERVICE_FTP = 1
    
    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 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 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 InternetCloseHandle Lib "wininet.dll" _
    (ByVal hInet As Long) As Integer

    Code to send file:

    Code:
    mlngSession = InternetOpen("Test Connect", INTERNET_OPEN_TYPE_PROXY, vbNullString, vbNullString, 0)
    
    mlngConnection = InternetConnect(mlngSession, txtHost.Text, INTERNET_INVALID_PORT_NUMBER, txtUser.Text, txtPass.Text, INTERNET_SERVICE_FTP, 0, 0)
    
    blnResult = FtpPutFile(mlngConnection, LocalFile, RemoteFile, 1, 0)
    
    InternetCloseHandle mlngConnection
    I hope this works, I just copied it out of a current project, can have some bugs :-)

    Roger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width