Thread: WinINet FtpPutFile problem

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    8

    WinINet FtpPutFile problem

    Hi, I am trying to upload a small file to server using WinINet and FtpPutFile function. The problem is that the FtpPutFile function doesn't work, something has to be wrong somewhere. Here is my code:
    Code:
    #include <windows.h>
    #include <iostream>
    #include <wininet.h>
    
    using namespace std;
    
    int main() {
    
        HINTERNET hSession = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
        HINTERNET hService = InternetConnect(hSession, "www.server.com", INTERNET_DEFAULT_FTP_PORT, "username", "password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
        FtpPutFile(hService, "filename.ext", "filename.ext", FTP_TRANSFER_TYPE_BINARY, 0);
        InternetCloseHandle(hService);
        InternetCloseHandle(hSession);
    
        return 0;
    }
    So, where could be the problem? FtpPutFile returns false.

    Thanks in advance,
    Anvar.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Your code looks alright. How about providing us with an error number:

    Code:
    int main() {
    
        HINTERNET hSession = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
    
    if (!hSession) printf("InternetOpen: %d", GetLastError());
    
        HINTERNET hService = InternetConnect(hSession, "www.server.com", INTERNET_DEFAULT_FTP_PORT, "username", "password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
    
    if (!hService) printf("InternetConnect: %d", GetLastError());
    
        BOOL bRet = FtpPutFile(hService, "filename.ext", "filename.ext", FTP_TRANSFER_TYPE_BINARY, 0);
    
    if (!bRet) printf("FtpPutFile: %d", GetLastError());
    
        InternetCloseHandle(hService);
        InternetCloseHandle(hSession);
    
        return 0;
    }

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    8
    Oh, thanks, I figured it out and it seems that the problem is in the server which doesn't support passive transferring... I replaced the INTERNET_FLAG_PASSIVE with 0 and now it works great! Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM