Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WinInet FtpPutFile

WinInet FtpPutFile

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminagentic-aihelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rbrad12345
    wrote on last edited by
    #1

    Hello everyone, I'm writing a simple class to handle FTP SEND of a file from a WinCE 4.2 box. I'm having some trouble with the FtpPutFile call. I've tried several FTP servers using a valid username & password and get the same error every time. InternetOpen succeeds, InternetConnect succeeds, FtpPutFile returns FALSE, GetLastError returns 12018. The error message 12018 is defined in WinInet.h as follows #define ERROR_INTERNET_INCORRECT_HANDLE_TYPE 12018 The type of handle supplied is incorrect for this operation. Any input is greatly appreciated! void CWinInetTestDlg::OnPut() { DWORD err = 0; CString str; HINTERNET hInternet = 0; // InternetOpen Params LPCTSTR agent = _T("FTP"); DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG; LPCTSTR proxy = 0; LPCTSTR bypass = 0; DWORD flags = 0; // InternetConnect Params LPCTSTR server = _T("X.X.X.X"); INTERNET_PORT port = INTERNET_DEFAULT_FTP_PORT; LPCTSTR user = _T("user_name"); LPCTSTR pass = _T("password"); DWORD service = INTERNET_SERVICE_FTP; DWORD context = 0; // FtpPutFile Params LPCTSTR szLocalFile = _T("\\TEST.TXT"); LPCTSTR szRemoteFile = _T("\\TEST.TXT"); hInternet = InternetOpen(agent, dwAccessType, proxy, bypass, flags); if (hInternet) { //flags = INTERNET_FLAG_PASSIVE; flags = 0; if (InternetConnect( hInternet, server, port, user, pass, service, flags, context)) { flags = INTERNET_FLAG_TRANSFER_BINARY; if ( FtpPutFile( hInternet, szLocalFile, szRemoteFile, flags, context) ) { MessageBox( _T("FtpPutFile Success!"), _T("WinInet FTP Test"), MB_OK); }else{ err = GetLastError(); str.Format(_T("FtpPutFile Error: %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//FTPPutFile }else{ err = GetLastError(); str.Format(_T("InternetConnect Error: %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetConnect if (!InternetCloseHandle(hInternet)) { err = GetLastError(); str.Format(_T("Error %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetCloseHandle }else{ err = GetLastError(); str.Format(_T("InternetOpen Failed with code %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetOpen } -Ryan Bradley

    M Z 2 Replies Last reply
    0
    • R rbrad12345

      Hello everyone, I'm writing a simple class to handle FTP SEND of a file from a WinCE 4.2 box. I'm having some trouble with the FtpPutFile call. I've tried several FTP servers using a valid username & password and get the same error every time. InternetOpen succeeds, InternetConnect succeeds, FtpPutFile returns FALSE, GetLastError returns 12018. The error message 12018 is defined in WinInet.h as follows #define ERROR_INTERNET_INCORRECT_HANDLE_TYPE 12018 The type of handle supplied is incorrect for this operation. Any input is greatly appreciated! void CWinInetTestDlg::OnPut() { DWORD err = 0; CString str; HINTERNET hInternet = 0; // InternetOpen Params LPCTSTR agent = _T("FTP"); DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG; LPCTSTR proxy = 0; LPCTSTR bypass = 0; DWORD flags = 0; // InternetConnect Params LPCTSTR server = _T("X.X.X.X"); INTERNET_PORT port = INTERNET_DEFAULT_FTP_PORT; LPCTSTR user = _T("user_name"); LPCTSTR pass = _T("password"); DWORD service = INTERNET_SERVICE_FTP; DWORD context = 0; // FtpPutFile Params LPCTSTR szLocalFile = _T("\\TEST.TXT"); LPCTSTR szRemoteFile = _T("\\TEST.TXT"); hInternet = InternetOpen(agent, dwAccessType, proxy, bypass, flags); if (hInternet) { //flags = INTERNET_FLAG_PASSIVE; flags = 0; if (InternetConnect( hInternet, server, port, user, pass, service, flags, context)) { flags = INTERNET_FLAG_TRANSFER_BINARY; if ( FtpPutFile( hInternet, szLocalFile, szRemoteFile, flags, context) ) { MessageBox( _T("FtpPutFile Success!"), _T("WinInet FTP Test"), MB_OK); }else{ err = GetLastError(); str.Format(_T("FtpPutFile Error: %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//FTPPutFile }else{ err = GetLastError(); str.Format(_T("InternetConnect Error: %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetConnect if (!InternetCloseHandle(hInternet)) { err = GetLastError(); str.Format(_T("Error %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetCloseHandle }else{ err = GetLastError(); str.Format(_T("InternetOpen Failed with code %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetOpen } -Ryan Bradley

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Two problems. 1) InternetConnect() return a HINTERNET but you're treating it like it returns a bool. 2) You're passing the wrong handle to FtpPutFile(), you need to pass it the handle returned by InternetConnect(). --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      R 1 Reply Last reply
      0
      • M Michael Dunn

        Two problems. 1) InternetConnect() return a HINTERNET but you're treating it like it returns a bool. 2) You're passing the wrong handle to FtpPutFile(), you need to pass it the handle returned by InternetConnect(). --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        R Offline
        R Offline
        rbrad12345
        wrote on last edited by
        #3

        Outstanding! Thank you! Ryan Bradley Systems Engineer Industrial Networks

        1 Reply Last reply
        0
        • R rbrad12345

          Hello everyone, I'm writing a simple class to handle FTP SEND of a file from a WinCE 4.2 box. I'm having some trouble with the FtpPutFile call. I've tried several FTP servers using a valid username & password and get the same error every time. InternetOpen succeeds, InternetConnect succeeds, FtpPutFile returns FALSE, GetLastError returns 12018. The error message 12018 is defined in WinInet.h as follows #define ERROR_INTERNET_INCORRECT_HANDLE_TYPE 12018 The type of handle supplied is incorrect for this operation. Any input is greatly appreciated! void CWinInetTestDlg::OnPut() { DWORD err = 0; CString str; HINTERNET hInternet = 0; // InternetOpen Params LPCTSTR agent = _T("FTP"); DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG; LPCTSTR proxy = 0; LPCTSTR bypass = 0; DWORD flags = 0; // InternetConnect Params LPCTSTR server = _T("X.X.X.X"); INTERNET_PORT port = INTERNET_DEFAULT_FTP_PORT; LPCTSTR user = _T("user_name"); LPCTSTR pass = _T("password"); DWORD service = INTERNET_SERVICE_FTP; DWORD context = 0; // FtpPutFile Params LPCTSTR szLocalFile = _T("\\TEST.TXT"); LPCTSTR szRemoteFile = _T("\\TEST.TXT"); hInternet = InternetOpen(agent, dwAccessType, proxy, bypass, flags); if (hInternet) { //flags = INTERNET_FLAG_PASSIVE; flags = 0; if (InternetConnect( hInternet, server, port, user, pass, service, flags, context)) { flags = INTERNET_FLAG_TRANSFER_BINARY; if ( FtpPutFile( hInternet, szLocalFile, szRemoteFile, flags, context) ) { MessageBox( _T("FtpPutFile Success!"), _T("WinInet FTP Test"), MB_OK); }else{ err = GetLastError(); str.Format(_T("FtpPutFile Error: %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//FTPPutFile }else{ err = GetLastError(); str.Format(_T("InternetConnect Error: %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetConnect if (!InternetCloseHandle(hInternet)) { err = GetLastError(); str.Format(_T("Error %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetCloseHandle }else{ err = GetLastError(); str.Format(_T("InternetOpen Failed with code %d"), err); MessageBox(str, _T("WinInet FTP Test"),MB_OK); }//InternetOpen } -Ryan Bradley

          Z Offline
          Z Offline
          ZoyaKhan18
          wrote on last edited by
          #4

          Will you please share your code.

          hi

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups