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;
}