Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm looking for a way to connect to one of our remote sites via FTP. I've 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.

Posted

here's an easy way to download files:

 

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 

Posted

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 it's first line was to include the WinInet.h file:

#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.xtremedotnettalk.com/attachment.php?attachmentid=&stc=1)

FTP.zip

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...