Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: 70N1 en 5 Septiembre 2013, 02:58 am



Título: Aver si podeis ayudar con este codigo: Wininet ftp
Publicado por: 70N1 en 5 Septiembre 2013, 02:58 am
Me vendria bien una mano....
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);
}


Título: Re: Aver si podeis ayudar con este codigo: Wininet ftp
Publicado por: Eternal Idol en 5 Septiembre 2013, 19:47 pm
Esto esta mal:
if (hTransfer == INVALID_HANDLE_VALUE)

Return value
Returns a handle if successful, or NULL otherwise. To retrieve a specific error message, call GetLastError.

FtpOpenFile esta fallando, ahora segui vos.