Thread: Please Help Me - Ftp Functions.

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Please Help Me - Ftp Functions.

    I'm trying to scan an ftp for any folders or Files that are on it. I can only get it do display the first file. Can someone PLEASE tell me whats wrong with the code below:

    Code:
    #include <windows.h>
    #include <Wininet.h>
    #include <iostream.h>
    
    int main()
    {
        WIN32_FIND_DATA pDirInfo;
    	WIN32_FIND_DATA pDir2Info;
        HINTERNET hDir;
    	HINTERNET intOpen;
    	HINTERNET hConnect;
    	char userName[100]="";
    	char password[100]="";
    	char server[100]="";
    
    	cout << "Enter the server: ";
    	cin  >> server;
    	cout << "Enter your user name: ";
    	cin  >> userName;
    	cout << "Enter your password: ";
    	cin  >> password;
    
    	intOpen = InternetOpen("ftp scan dos", INTERNET_OPEN_TYPE_DIRECT,
    		NULL, NULL,INTERNET_FLAG_ASYNC);
    	hConnect = InternetConnect(intOpen, server, INTERNET_DEFAULT_FTP_PORT,
    		userName, password, INTERNET_SERVICE_FTP, INTERNET_SERVICE_FTP, 0);
    
    	hDir = FtpFindFirstFile(hConnect, "*.*", &pDirInfo,
    			INTERNET_FLAG_DONT_CACHE, 0);
    	cout << "\nRoot Dir Contains:\n" << pDirInfo.cFileName << "\n";
    
    	while(InternetFindNextFile (hDir, &pDirInfo))
    		cout << pDirInfo.cFileName << "\n";
    
       	return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    7

    Exclamation Ummm....

    You should probably not be using a third part Winsock library. If you want to break down ho winsock really works, you should learn the API. Get a couple Winsock programming tutorials, the help file for the Winsock API, and the FTP RF for the ftp commands.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Ummmm...

    Didn't I post a response to this thread?

    There is more than one file to find?

    Why are you not using INTERNET_FLAG_RELOAD as well as 'no cache' to ensure the files are current?

    Try rewritting your while loop. Check GetLastError() for ERROR_NO_MORE_FILES and also for an invalid file handle.
    This may tell you WHY the while loop is exiting.

    (I would have used a Do-While as the loop has to execute at least once)

    Don't forget to call for a close on the handle or you will not be able to open another.

    Why are you using 'main' and not 'winmain' in a windows app?
    Doesn't your compiler complain it can't find the winmain? Or did you not create a WIN32 APP? (not a WIN32 console app)

    >>third part Winsock library
    WinInet.h is the MS WIN32 Internet Extensions header. Not exactly third party. But also not as low level as the Windows Sockets API (allows quick development as you can ignore WinSock, TCP/IP ect).
    Last edited by novacain; 10-15-2002 at 09:01 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to program in unix
    By Cpro in forum Linux Programming
    Replies: 21
    Last Post: 02-12-2008, 10:54 AM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Ftp Help
    By D@rk_force in forum C++ Programming
    Replies: 13
    Last Post: 12-27-2004, 02:50 PM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM