No lee el archivo con InternetReadFile.
Código:
void main()
{
HINTERNET hSession = InternetOpen(L"WinInet Progress Sample",
INTERNET_OPEN_TYPE_DIRECT,
NULL,
NULL,
INTERNET_FLAG_PASSIVE);
HINTERNET hConnection = InternetConnect(hSession,L"LESCOMEDIENSPLUS.BESABA.COM", // Server
21,
L"u115059645", // Username
L"toni12883", // Password
INTERNET_SERVICE_FTP,
1, // Synchronous
NULL); // No Context
// Download a file
HINTERNET hTransfer = NULL;
HANDLE hFileDownload = NULL;
TCHAR tchName[MAX_PATH] = TEXT("public_html\\test.sql");
// Open the transfer
hTransfer = FtpOpenFile(hConnection, tchName, GENERIC_READ,
FTP_TRANSFER_TYPE_ASCII, 0);
if (hTransfer == INVALID_HANDLE_VALUE)
{
printf("Unable to open remote File");
system("pause");
return;
}
// Ok, the file transfer is active. Create a new file to write to
hFileDownload = CreateFile(TEXT("c:\\index.txt"), GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileDownload == INVALID_HANDLE_VALUE)
{
printf("Unable to open Destination File");
return;
}
// Looks like everything's ok, so use InternetReadFile to download
// the file
char data_from_url[4096];
DWORD NumberOfBytesRead = 0;
while(InternetReadFile(hTransfer, data_from_url, 4096, &NumberOfBytesRead) && NumberOfBytesRead )
{
cout << data_from_url;
}
system("pause");
CloseHandle(hFileDownload);
InternetCloseHandle(hTransfer);
}