Thread: FTP program help

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    108

    FTP program help

    i´m trying to connect to a machine on my LAN network and download a file from the c drive.

    using this program i have already managed to download a file from various FTP sites and save it locally, successfully.

    however, when i modified the code to point to the machine in my office, the program runs until the printf "downloading data" and then suddently skips to "press any key to continue".

    it doesnt give me any output file either. i am probably making an easy error somewhere and would like any input

    thanks

    Code:
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <Wininet.h>
    
    int main ()
    
    {
    
    //filename to get
    char filename[12]="h10.ems";
    //remote computer
    char hostname[BUFSIZ]="pcecureeev2.gmv.com";
    //directory where file is
    char directory[BUFSIZ] = "c:\\";
    
    //printf("please enter ftp site\n");
    //scanf("%c", &hostname);
    
    HINTERNET hSession;
    hSession = InternetOpen("MyApp", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    
    	if (hSession)
    	{ HINTERNET hService;
        hService = InternetConnect(hSession, hostname, 
                                   INTERNET_DEFAULT_FTP_PORT, "NULL", "NULL", 
                                   INTERNET_SERVICE_FTP, 0, 0);
    
    	if (InternetConnect==NULL)
    	{
    		printf("connection could not be established");
    	}
    
    	printf("Downloading.....please wait\n");
    
        if (hService)
        {
            if (!FtpSetCurrentDirectory(hService, directory))
            {
                printf("Error changing directory\n");
            }    
            if (FtpGetFile(hService, filename, "c:\\TEMP\\h10.ems",
                FALSE, 0, FTP_TRANSFER_TYPE_ASCII, 0))
            {
                printf("file download successful\n");
            }else{
                printf("Error getting file\n");
    			}
            InternetCloseHandle(hService);
        }
    }
    	InternetCloseHandle(hSession);
    	return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you even have permission to read from your C drive over a network?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Well it seems that even formatting has fallen on deaf ears
    http://cboard.cprogramming.com/showthread.php?t=67376

    1. Have you bothered to try to connect to your machine using a normal (ie working) ftp program?

    2. Look at the configuration of the FTP server on your machine (do you even have one). Most have a concept of a local root which is well down from c:\ and the chance to do all sorts of damage to your machine.

    3. Firewalls.

    4. printf("Error getting file\n");
    Yeah, and I'm sure there are all sorts of error codes which would give more information if you bothered to look.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
        hService = InternetConnect(hSession, hostname, 
                                   INTERNET_DEFAULT_FTP_PORT, "NULL", "NULL", 
                                   INTERNET_SERVICE_FTP, 0, 0);
    If you're trying to use the anonymous logon, you should use the constant NULL, rather than the string "NULL".

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    i´ll check these and get back to you...

    and i do have permission to access the computer over an ftp network

    i have tried using a program called MAX-FTP to access the computer using the exact same details and the only error i get is for a wrong password.

    could that be the problem?

    how would i put in the code to identify errors, i tried it but cant get it to work
    Last edited by shoobsie; 07-19-2005 at 04:49 AM.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    ok, i managed to connect succesfully and receive a file. but is there a function that allows you to download a directory?

    a bit like "Getdirectory" or something?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > how would i put in the code to identify errors, i tried it but cant get it to work
    Download ethereal (this is all mentioned in the network programming board) http://cboard.cprogramming.com/forumdisplay.php?f=28
    Get traces of what a real FTP program does, and what YOUR FTP program does.
    Compare the sequence and content of messages until you find a difference.

    Then try and understand why that difference exists.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  3. How can I run a small ftp script from C program
    By bazeemuddin in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-01-2003, 05:04 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM