Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
All Other Wrox Books Do you have a question about a Wrox book that isn't listed anywhere on p2p.wrox.com or where the forum is locked? Here's a forum to post questions about any other Wrox book so that other readers or one of the authors can help you with your questions. IF YOU ARE LOOKING FOR CODE DO NOT ASK "Where can I find the code for this book?" That question is answered here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the All Other Wrox Books section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 6th, 2008, 08:22 PM
Registered User
 
Join Date: Oct 2008
Location: Sydney, NSW, Australia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default FTPGet

G'day,
I want to download a file from an FTP site, programmatically.
The code included runs in MSAccess 2002 running under Windows XP pro.
The same sode compiles under Visual Studio 2003 but always returns False from the FtpGet() function. I have installed Service Pack 1.


    Private 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


    Private 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

    Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" ( _
      ByVal hFtpSession As Long, _
      ByVal lpszRemoteFile As String, _
      ByVal lpszNewFile As String, _
      ByVal fFailIfExists As Boolean, _
      ByVal dwFlagsAndAttributes As Long, _
      ByVal dwFlags As Long, _
      ByVal dwContext As Long) As Boolean

    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

    Private Sub btnFTP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFTP.Click

        Const ftpServerName = "Enter your server address"
        Const UserName = "Enter your Username"
        Const Password = "Enter your password"

        Const FTP_PATH = "Enter the path on your FTP server" ' No leading '/'
    const FTP_FILE = FTP_PATH & "FTPfile.txt"

        Const LOCAL_PATH = "Enter your local path to receive the downloaded file"
        const LOCAL_FILE = LOCAL_PATH & "LocalFile.txt"

        Dim lngINet As Long, lngINetConn As Long, blnRC As Boolean


        'Open an Internet session without using a proxy
        lngINet = InternetOpen("SessionName", 1, vbNullString, vbNullString, 0)

        'Connect to the host
        lngINetConn = InternetConnect(lngINet, ftpServerName, 21, UserName, Password, 1, 0, 0) 'OK

        'In case the local file already exists, we’ll overwrite it.
        blnRC = FtpGetFile(lngINetConn, RemoteFile, LocalFile, 0, 0, 1, 0)

        If blnRC Then
        ' I ALWAYS end up here!?
            ' Indicates that the download failed, which it did!
            MessageBox.Show("DOWNLOAD was successfull!")
        Else
            MessageBox.Show("Download FAILED!")
        End If

        ' Close handles
        InternetCloseHandle(lngINetConn)
        InternetCloseHandle(lngINet)

    End Sub

I must have an environment problem with Visual Sudio! Please help!
  #2 (permalink)  
Old October 6th, 2008, 09:20 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

What kind of VS2003 project *is* this???? VB.NET? ASP.NET? What?

But if it is *any* kind of .NET project, you shouldn't be using the old fashioned wininet.dll methodology. You should be moving to standard .NET classes and interfaces.

Since you posted this in the "Other Books", can you say what WROX book you got the code out of???
  #3 (permalink)  
Old October 6th, 2008, 11:44 PM
Registered User
 
Join Date: Oct 2008
Location: Sydney, NSW, Australia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

G'day Old Pedant,
thank you for replying. This is my first VB.NET project. I am hoping to upgrade an MSAccess 2002 database. This is the preliminary stage, solving the difficult problems first.
I found the code in "FTP from inside VB.NET Program" on this forum. Some users can get it to work while other are having the same problem I have.
Can you be more specific about "standard .NET classes"? This is my first attempt at a .net project.
Where can I get more information?
Regards, mccer

  #4 (permalink)  
Old October 7th, 2008, 12:24 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Was actually going to point you to the docs earlier, but MSDN was being its periodically usual useless self. Seems to be fixed now.

http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp(VS.80).aspx

http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp_members(VS.80).as px

Unfortunately, those docs have no usable examples in them, so you might try a query in MSDN, such as this one:

http://social.msdn.microsoft.com/Sea...thods.Ftp&ac=8

or try googling for "examples webrequestmethods.ftp"

Should find plenty of hits.








Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.