How to FTP

joe_pool_is

Well-known member
Joined
Jan 18, 2004
Messages
451
Location
Texas
Im looking for a way to connect to one of our remote sites via FTP. Ive been searching MSDN, but so far I am unable to find a topic detailing how to do this. The closest I found was an article on IIS, which may now encapsulate FTP features. I was not readily able to see how to get my application to do basic FTP commands, however.

My application need to connect to ftp into the server and download a small text file after booting up (this text file will function as a security key). Occasionally, as updates come out, this small text file will also notify the program that it needs to download the latest patches.

What keywords should I be looking under? I have been using "ftp sdk" and "ftp skd msdn", but these pulled up lists that were not what I wanted.
 
Interesting Jam Man. Your "updater" seems to be just what I am looking for using XML. I will look into it. Thanks.
 
heres an easy way to download files:

Code:
Option Strict Off
Option Explicit On 

Imports System.Runtime.InteropServices

Module FTPDownload
    Dim frm1 As Form1
    Private Declare Function InternetCloseHandle Lib "wininet.dll" _
        (ByVal hInternet As IntPtr) As Boolean

    Private Declare Auto Function InternetOpen Lib "wininet.dll" _
        (ByVal lpszAgent As String, _
         ByVal lAccessType As Integer, _
         ByVal lpszProxyName As String, _
         ByVal lpszProxyBypass As String, _
         ByVal dwFlags As Integer) As IntPtr

    Private Declare Auto Function InternetConnect Lib "wininet.dll" _
        (ByVal hInternet As IntPtr, _
         ByVal lpszServerName As String, _
         ByVal nServerPort As Short, _
         ByVal lpszUserName As String, _
         ByVal lpszPassword As String, _
         ByVal dwService As Integer, _
         ByVal dwFlags As Integer, _
         ByVal dwContext As Integer) As IntPtr

    Private Declare Auto Function FtpGetFile Lib "wininet.dll" _
        (ByVal hConnect As IntPtr, _
         ByVal lpszRemoteFile As String, _
         ByVal lpszNewFile As String, _
         ByVal fFailIfExists As Boolean, _
         ByVal dwFlagsAndAttributes As Integer, _
         ByVal dwFlags As Integer, _
         ByVal dwConext As Integer) As Boolean

    Private Declare Auto Function FtpPutFile Lib "wininet.dll" _
        (ByVal hConnect As IntPtr, _
         ByVal lpszLocalFile As String, _
         ByVal lpszNewRemoteFile As String, _
         ByVal dwFlags As Integer, _
         ByVal dwContext As Integer) As Boolean
    Dim currentnumber As Integer
    Sub Main()

        currentnumber = currentnumber + 1
        Dim hInet As IntPtr
        Dim hConn As IntPtr

        hInet = InternetOpen("my ftp", 1, vbNullString, vbNullString, 0)
        Console.WriteLine("hInet = {0}", hInet)

        hConn = InternetConnect(hInet, "no.prefix.com", 21, "", _
 "", 1, 0, 0)
        Console.WriteLine("hConn = {0}", hConn)

        Console.WriteLine("FtpGetFile Result = {0}", FtpGetFile(hConn, _
"folder/in/ftp.txt", "locationftp.txt", True, 1, 1, 0))

        InternetCloseHandle(hConn)
        InternetCloseHandle(hInet)
    End Sub
 
I am using MFC and C++ in my ftp program (the targets that run it will not have the .NET framework installed).

I followed a nice little example on downloading files via ftp, and its first line was to include the WinInet.h file:
Code:
#include <wininet.h>
When I try to compile my small program, I get errors that point back to code that is declared in the WinInet.h file.

I have started to include other header files that include definitions to things that WinInet.h needs (i.e. DWORD in windef.h), but now I am getting errors in the declarations found in those new files!

Does someone know if there is a basic header file that I missed somewhere? (code is in this ftp zip file http://www.computerhelp.forum/attachment.php?attachmentid=&stc=1)
 

Attachments

Back
Top