Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. FSDFtpC::getInstance().UploadFile("ftp.jqe360.com", 21, "updates@jqe360.com", "xbox360", "debug.log", "game:\\");
  2.  
  3. above is call; below is function.
  4.  
  5. void FSDFtpC::UploadFile(string host, int port, string username, string password, string filename, string path)
  6. {
  7.  
  8.     DebugMsg("FSDFtpC", "Starting process");
  9.     netbuf *conn;
  10.  
  11.     XNDNS* m_pXNDns;
  12.     HANDLE hEvent = CreateEvent(NULL, false, false, NULL);
  13.            
  14.     INT iErr = XNetDnsLookup(
  15.         host.c_str(),         // a string that prepresents the host name
  16.         hEvent,          // the event handle from the CreateEvent call
  17.         &m_pXNDns);      // the XNDNS structure to receive the IP info for the DNS entry found.
  18.    
  19.     while (m_pXNDns->iStatus == WSAEINPROGRESS)
  20.     {
  21.         WaitForSingleObject(hEvent, INFINITE);
  22.     }
  23.     CloseHandle(hEvent);
  24.            
  25.     if (m_pXNDns->cina != 0 && m_pXNDns->iStatus == 0)
  26.     {
  27.         char *buffer;
  28.         XNetInAddrToString(m_pXNDns->aina[0], buffer, 32);
  29.         //host = sprintfaA("%s", buffer);
  30.         XNetDnsRelease(m_pXNDns);
  31.         DebugMsg("FTPTest", "Connecting to %s", buffer);
  32.         if (!FtpConnect(buffer,21, &conn))
  33.         {
  34.             DebugMsg("FTPTest", "Failed to open connection");
  35.             return;
  36.         }
  37.     } else {   
  38.         DebugMsg("FTPTest", "Connecting to %s", host.c_str());
  39.         if (!FtpConnect(host.c_str(),21, &conn))
  40.         {
  41.             DebugMsg("FTPTest", "Failed to open connection");
  42.             return;
  43.         }
  44.     }
  45.    
  46.     DebugMsg("FTPTest", "Logining in");
  47.     DebugMsg("FTPClient", "Username: %s, Password: %s", username.c_str(), password.c_str());
  48.     if (!FtpLogin(username.c_str(), password.c_str(), conn))
  49.     {
  50.         DebugMsg("FTPTest", "Failed to login");
  51.         FtpClose(conn);
  52.         return;
  53.     }
  54.    
  55.     string localfilename = path + filename;
  56.     string remotefilename = sprintfaA("/%s", filename.c_str());
  57.     if(!FtpPut(localfilename.c_str(), remotefilename.c_str(), FTPLIB_BINARY, conn))
  58.     {
  59.         DebugMsg("FTPTest", "Upload Failed");
  60.         FtpClose(conn);
  61.         return;
  62.     }
  63.  
  64.     FtpClose(conn);
  65.     return;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement