title: C++ - Internet connection, logging to local network
body: <p>I'd like to ask you one question. I got a code to send file to an FTP server. It's doing well if we have correct internet connection. But I have one problem. At place where this program is supposed to work, internet access is.. let's say limited. I mean for example if I open browser there's a prompt for access to a local network, then I can use internet. Otherwise I can't use it. So, my point is to add into code possibility to connect my network with username and password. I really don't know how to do it :( Please, help me :)
  Here's the code of sending FTP file:</p>
  
  <pre><code>int UploadFTP::SubmitFile(std::string localFile) {
  
  ServerData data;
  char computerName[MAX_COMPUTERNAME_LENGTH + 1];
  DWORD buffer = MAX_COMPUTERNAME_LENGTH + 1;
  if(GetComputerName(computerName, &amp;buffer) == 0) printf("ComputerNameGetFail\n");
  std::string remoteFile;
  remoteFile = std::string(computerName) + "(" +  GetTimeString() + std::string(".txt");
  for(int i=0;i&lt;remoteFile.length();i++) {
      if(remoteFile[i] == '\n') remoteFile[i] = ')';
      if(remoteFile[i] == ':' || remoteFile[i] == '/') remoteFile[i] = '-';
  }
  
  HINTERNET hInternet;
  HINTERNET hFtpSession;
  
  if(InternetAttemptConnect(0) == ERROR_SUCCESS) printf("Send.Init...\n");else printf("Conn.Err.\n");
  
  hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
  if(hInternet != NULL) {
      hFtpSession = InternetConnect(hInternet, data.serverIP.c_str(), INTERNET_DEFAULT_FTP_PORT, data.userName.c_str(), data.password.c_str(), INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
      if(hFtpSession != NULL) {
          if(FtpPutFile(hFtpSession, localFile.c_str(), remoteFile.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) {
              InternetCloseHandle(hFtpSession);
              InternetCloseHandle(hInternet);
              printf("Sent ok!\n");
          }else {
              printf("Send err.\n");
              DWORD err = GetLastError();
              printf("ERR: %x\n",err);
              InternetCloseHandle(hFtpSession);
              InternetCloseHandle(hInternet);
              return -1;
          }
      }else {
          printf("Can't reach conn.\n");
          InternetCloseHandle(hInternet);
          return -1;
      }
  }else {
      printf("Conn. err.\n");
      return -1;
  }
  
  return 0;
  </code></pre>
  
  <p>}</p>