MCPcopy Create free account
hub / github.com/EasyIME/PIME / openFtpFile

Function openFtpFile

installer/inetc/Contrib/Inetc/inetc.cpp:509–634  ·  view source on GitHub ↗

* FUNCTION NAME: openFtpFile() * PURPOSE: * control connection, size request, re-get lseek * SPECIAL CONSIDERATIONS: * *****************************************************/

Source from the content-addressed store, hash-verified

507*
508*****************************************************/
509HINTERNET openFtpFile(HINTERNET hConn,
510 TCHAR *path)
511{
512 TCHAR buf[256] = TEXT(""), *movp;
513 HINTERNET hFile;
514 DWORD rslt, err, gle;
515 bool https_req_ok = false;
516
517 /* reads connection / auth responce info and cleares 'control' buffer this way */
518 InternetGetLastResponseInfo(&err, buf, &(rslt = sizeof(buf)));
519 if(cnt == 0)
520 {
521 if(!fput) // we know local file size already
522 {
523 if (myFtpCommand)
524 {
525 /* Try to set the REPRESENTATION TYPE to I[mage] (Binary) because some servers
526 don't accept the SIZE command in ASCII mode */
527 myFtpCommand(hConn, false, FTP_TRANSFER_TYPE_ASCII, TEXT("TYPE I"), 0, &hFile);
528 }
529 /* too clever myFtpCommand returnes false on the valid TEXT("550 Not found/Not permitted" server answer,
530 to read answer I had to ignory returned false (!= 999999) :-(
531 GetLastError also possible, but MSDN description of codes is very limited */
532 wsprintf(buf, TEXT("SIZE %s"), path + 1);
533 if(myFtpCommand != NULL &&
534 myFtpCommand(hConn, false, FTP_TRANSFER_TYPE_ASCII, buf, 0, &hFile) != 9999 &&
535 memset(buf, 0, sizeof(buf)) != NULL &&
536 InternetGetLastResponseInfo(&err, buf, &(rslt = sizeof(buf))))
537 {
538 if(_tcsstr(buf, TEXT("213 ")))
539 {
540 fs = myatou(_tcschr(buf, TEXT(' ')) + 1);
541 }
542 /* stupid ProFTPD returns error on SIZE request. let's continue without size.
543 But IE knows some trick to get size from ProFTPD......
544 else if(mystrstr(buf, TEXT("550 TEXT("))
545 {
546 status = ERR_SIZE_NOT_PERMITTED;
547 return NULL;
548 }
549 */
550 }
551 if(fs == 0)
552 {
553 fs = NOT_AVAILABLE;
554 }
555 }
556 }
557 else
558 {
559 wsprintf(buf, TEXT("REST %d"), cnt);
560 if(myFtpCommand == NULL ||
561 !myFtpCommand(hConn, false, FTP_TRANSFER_TYPE_BINARY, buf, 0, &hFile) ||
562 memset(buf, 0, sizeof(buf)) == NULL ||
563 !InternetGetLastResponseInfo(&err, buf, &(rslt = sizeof(buf))) ||
564 (_tcsstr(buf, TEXT("350")) == NULL && _tcsstr(buf, TEXT("110")) == NULL))
565 {
566 status = ERR_REGET;

Callers 1

inetTransferFunction · 0.85

Calls 3

memsetFunction · 0.85
myatouFunction · 0.85
GetWininetProcAddressFunction · 0.85

Tested by

no test coverage detected