MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / openFtpFile

Function openFtpFile

cmake/Windows/Contrib/Inetc/inetc.cpp:504–629  ·  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

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