ResumeReceiveFilePASV Resumes retrieving the specified file from the currently connected FTP site. The file is then saved to the specified destination file. This routine duplicates the ReceiveFile() member, but in this routine the client originates data connections. Client side origination of data connections is preferred for use in firewall controlled
| 621 | UTE_CONNECT_TIMEOUT - connection timeout |
| 622 | ****************************************/ |
| 623 | int CUT_FTPClient::ResumeReceiveFilePASV(CUT_DataSource & dest, LPCSTR sourceFile) { |
| 624 | |
| 625 | UINT loop; |
| 626 | int rt, error; |
| 627 | char responseBuf[100]; |
| 628 | int port; |
| 629 | char ipAddress[20]; |
| 630 | char *token; |
| 631 | OpenMsgType fileType = UTM_OM_WRITING; // by default we will write a file unless it exist |
| 632 | // then we will append to it |
| 633 | |
| 634 | |
| 635 | |
| 636 | //send the port command |
| 637 | Send("PASV\r\n"); |
| 638 | |
| 639 | m_wsData.SSLSetReuseSession(SSLGetCurrentSession()); |
| 640 | |
| 641 | // we need to get the full IP address and port number from the |
| 642 | // PASV return line, so that we can originate the data connection. |
| 643 | |
| 644 | //check for a return of 2??, which indicates success |
| 645 | rt = GetResponseCode( this, responseBuf, sizeof(responseBuf) ); |
| 646 | if(rt < 200 || rt >299) |
| 647 | return OnError(UTE_PORT_FAILED); |
| 648 | |
| 649 | |
| 650 | // find the first '(' in the response and then parse out |
| 651 | // the address supplied by the server |
| 652 | loop = 0; |
| 653 | while ( loop < strlen(responseBuf) ){ |
| 654 | if ( responseBuf[loop] == '(' ) |
| 655 | break; |
| 656 | loop++; |
| 657 | } |
| 658 | |
| 659 | if ( loop == strlen(responseBuf) ) // we hit the end of the buffer |
| 660 | return OnError(UTE_RETR_FAILED); |
| 661 | |
| 662 | // token out the ipaddress and port string |
| 663 | token = strtok( &responseBuf[loop], "()" ); |
| 664 | |
| 665 | // get the four portions of the ip address |
| 666 | strcpy(ipAddress, strtok( token, ",)\r\n" )); |
| 667 | strcat(ipAddress, "."); |
| 668 | strcat(ipAddress, strtok( NULL, ",)\r\n" )); |
| 669 | strcat(ipAddress, "."); |
| 670 | strcat(ipAddress, strtok( NULL, ",)\r\n" )); |
| 671 | strcat(ipAddress, "."); |
| 672 | strcat(ipAddress, strtok( NULL, ",)\r\n" )); |
| 673 | |
| 674 | // get the two portions that make up the port number |
| 675 | port = atoi( strtok(NULL, ",)\r\n") ) * 256; |
| 676 | port += atoi( strtok(NULL, ",)\r\n") ); |
| 677 | |
| 678 | // test the results to ensure everything is OK. |
| 679 | if ( !IsIPAddress(ipAddress) ) |
| 680 | return OnError(UTE_SVR_DATA_CONNECT_FAILED); |
nothing calls this directly
no test coverage detected