Thread: Problem with FtpFindFirstFile

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    142

    Problem with FtpFindFirstFile

    I have a strange problem with ftp download.

    Here is my code, I removed error messages UI for clarity.

    Code:
       BOOL            bSuccess, bFileOK = FALSE;
       int             lastErr = 0;
       char            tmpStr[256];
       HINTERNET       hIntSession = NULL, hFtpSession = NULL, hFind = NULL;
       WIN32_FIND_DATA findData;
    	
       hIntSession = InternetOpen ("Mozilla/4.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0/*INTERNET_FLAG_ASYNC*/);
       
       if (hIntSession)  {
          hFtpSession = InternetConnect (hIntSession,
                                         ftpServerName,
                                         INTERNET_DEFAULT_FTP_PORT,
                                         ftpUserName, ftpPassword,
                                         INTERNET_SERVICE_FTP, 0, 0);
          if (hFtpSession)  {
             bSuccess = FtpSetCurrentDirectory (hFtpSession, remoteDirStr);
    			
             if (bSuccess)  {
                hFind = FtpFindFirstFile (hFtpSession, "*", &findData, 0, 0);
    				
                if (hFind)  {
    Well, here it fails. InternetOpen() returns a valid session, InternetConnect() is ok, FtpSetCurrentDirectory() returns success, but FtpFindFirstFile() fails.

    If I connect with some ftp client software I can see files. It even doesn't work if I try to connect to my second computer and try to see something.

    Can anyone see a problem in my code? Application where I try to insert this functionality is not Unicode, it's an old project I need to support, so maybe that is somehow relevant.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    What error are you getting?
    To get a specific error message, call GetLastError. If GetLastError returns ERROR_INTERNET_EXTENDED_ERROR, as in the case where the function finds no matching files, call the InternetGetLastResponseInfo function to retrieve the extended error text, as documented in Handling Errors.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Thanks for your swift response.

    Yes, 12003 was the error reported. Now I googled for ERROR_INTERNET_EXTENDED_ERROR and found relevant information immediately. For some reason, googling for error 12003 wasn't so informative.

    Now I'll check what is InternetGetLastResponseInfo giving me...

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Heh, exact text:

    Last err: 200 TYPE is now ASCII
    500 I won't open a connection to 10.0.2.15 (only to 88.207.28.190)
    500 Unknown command

    Address 88.207.28.190 is my address, as I checked. 10.0.2.15 appears to be some garbage.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Just curious... have you tried the FtpFindFirstFile() with "*.*" or NULL instead of the single star?

    Also you might want to look at the flags for this function... INTERNET_FLAG_RESYNCHRONIZE might be relevant.

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Tried everything: "*.*", "*", "", NULL, .. you name it.

    MS - "If the value of lpszSearchFile is NULL or if it is an empty string, the function finds the first file in the current directory on the server."

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    My bad!

    I was doing this on Vista so when I moved that code to an XP box, just like that everything works well. This will teach me not to use Vista for development.

    Just kidding, since I'm a Mac person I have only one Vista and one XP PC. I can eliminate Vista as not my problem, but I have no clue if my ftp implementation would still work on 7. Trouble.

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You may have to run the exe as an admin on Vista for it to work. Alternatively if you are developing for Vista you can setup the UAC so it won't interfere with your program. I wouldn't be ok with the knoweldge that it runs on XP but not Vista because that will most likely mean it also does not run on Windows 7.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by idelovski View Post
    My bad!

    I was doing this on Vista so when I moved that code to an XP box, just like that everything works well. This will teach me not to use Vista for development.

    Just kidding, since I'm a Mac person I have only one Vista and one XP PC. I can eliminate Vista as not my problem, but I have no clue if my ftp implementation would still work on 7. Trouble.
    It may require a manifest in your program's resources... like this
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
      <assemblyIdentity type="win32"
                        name="AutoLogon"
                        version="1.0.0.0"
                        processorArchitecture="X86" />
      <description>
        Auto logon tool  
    </description>
      <dependency>
        <dependentAssembly>
          <assemblyIdentity type="win32"
                            name="Microsoft.Windows.Common-Controls"
                            version="6.0.0.0"
                            processorArchitecture="X86"
                            publicKeyToken="6595b64144ccf1df"
                            language="*" />
        </dependentAssembly>
      </dependency>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
          <requestedPrivileges>
            <requestedExecutionLevel  level="asInvoker" 
                                      uiAccess="false" /> 
          </requestedPrivileges>
        </security>
      </trustInfo>
    </assembly>
    The parts highlighted in blue are to be customized for your program.

  10. #10
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Did you ever resolve this?

    Did you ever resolve this problem? I've got the same thing on Windows 7 -- works fine on XP -- but with error 12002 instead. Ftp apps work fine. Just doesn't work with my code (dies with 12002 at FtpFindFirstFile).

  11. #11
    Registered User
    Join Date
    Mar 2007
    Posts
    142
    Not really,

    in other words, i have solved this with XP, luckily for me, I need this only at few places and they are all on XP. In the meantime, I was busy with my projects on Mac & iPhone so I'll probably return to this by the end of May or in June. If I find solution to this I promise to report back here.

    Have you tried calling InternetGetLastResponseInfo() function?
    Last edited by idelovski; 04-28-2011 at 02:06 PM.

  12. #12
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Hints

    Quote Originally Posted by idelovski View Post
    Have you tried calling InternetGetLastResponseInfo() function?
    No. I'm not familiar with that. I'll take a look.

    I have characterized it a little. My FtpFindFirstFile only hangs up when talking to a particular device using Windows 7. I can talk to my ftp-serving Mac just fine using the same code under Windows 7. And the code talks to anything when I run it under XP. I'll check out InternetGetLastResponseInfo.

  13. #13
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Fixed it!

    I stuck a call to InternetGetLastResponseInfo in there, but I'm not sure if that would have helped me because the error code I was fighting was 12002, to which that routine is supposedly not applicable. But I never ended up hitting the call because I noticed the INTERNET_FLAG_PASSIVE to InternetConnect, and once I added that in, it started working on Windows 7. Without it, everything hangs (and times out) but with it, I'm golden! Doesn't sound like that's your problem since you're getting a different error code, but if you revisit this and get it working, please do post your solution in case I or others end up needing it! Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM