How to use FTP?

This is a discussion on How to use FTP? within the C++ Programming forums, part of the General Programming Boards category; How can I access FTP with winsock. Can you give me a link with some examples or where I can ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    How to use FTP?

    How can I access FTP with winsock.
    Can you give me a link with some examples or where I can find the functions in MSDN.
    Got this far:
    Code:
    #include <windows.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    WSADATA wsaData;
    SOCKET m_socket;
    SOCKET AcceptSocket;
    sockaddr_in service;
    sockaddr_in clientService;
    int iResult;
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
    
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
                iResult=WSAStartup(MAKEWORD(2,2),&wsaData);
                if (iResult!=NO_ERROR){
                MessageBox(hwnd,"WSAStartup returned error!","Winsock",MB_OK);
                }
                m_socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
                if (m_socket==INVALID_SOCKET){
                MessageBox(hwnd,"Invalid socket","Winsock",MB_OK);
                }     
                service.sin_family = AF_INET;
                service.sin_addr.s_addr=inet_addr("127.0.0.1");
                service.sin_port=htons(21);
                if (bind(m_socket,(SOCKADDR*)&service,sizeof(service)) == SOCKET_ERROR){
                MessageBox(hwnd,"Bind socket","Winsock",MB_OK);
                closesocket(m_socket);
                }
                if (listen(m_socket,1)==SOCKET_ERROR){
                MessageBox(hwnd,"Error listening on socket.","Winsock",MB_OK);
                }
                AcceptSocket = SOCKET_ERROR;
                while (AcceptSocket==SOCKET_ERROR) {
                AcceptSocket =accept(m_socket,NULL,NULL);
                }
                MessageBox(hwnd,"Connected","Winsock",MB_OK);
                m_socket = AcceptSocket;
                clientService.sin_family =AF_INET;
                clientService.sin_addr.s_addr=inet_addr("195.222.29.64");
                clientService.sin_port=htons(21);
    }
    
                break;
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            case WM_COMMAND:
                switch(wParam){
                case 12345:
                    break;
                }
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    But the AcceptSocket loop is infinite...
    Last edited by maxorator; 11-04-2005 at 10:34 AM.

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Are you listening on port 21 on your computer? You would need an ftp server running to connect to yourself on that port.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    clientService.sin_addr.s_addr=inet_addr("195.222.2 9.64");
    I think I messed up and put server and client script into one file

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    #include <windows.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    WSADATA wsaData;
    SOCKET m_socket;
    SOCKET AcceptSocket;
    sockaddr_in service;
    sockaddr_in clientService;
    int iResult;
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Windows App",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
    
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
                iResult=WSAStartup(MAKEWORD(2,2),&wsaData);
                if (iResult!=NO_ERROR){
                MessageBox(hwnd,"WSAStartup returned error!","Winsock",MB_OK);
                }
                m_socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
                if (m_socket==INVALID_SOCKET){
                MessageBox(hwnd,"Invalid socket","Winsock",MB_OK);
                }     
                service.sin_family = AF_INET;
                service.sin_addr.s_addr=inet_addr("195.222.29.64");
                service.sin_port=htons(21);
                if (bind(m_socket,(SOCKADDR*)&service,sizeof(service)) == SOCKET_ERROR){
                MessageBox(hwnd,"Bind socket","Winsock",MB_OK);
                closesocket(m_socket);
                }
                if (listen(m_socket,1)==SOCKET_ERROR){
                MessageBox(hwnd,"Error listening on socket.","Winsock",MB_OK);
                }
                AcceptSocket = SOCKET_ERROR;
                while (AcceptSocket==SOCKET_ERROR) {
                AcceptSocket =accept(m_socket,NULL,NULL);
                }
                MessageBox(hwnd,"Connected","Winsock",MB_OK);
                break;
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            case WM_COMMAND:
                switch(wParam){
                case 12345:
                    break;
                }
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    But now bind always fails and the program goes not responding.
    195.222.29.64 is a web hosting with FTP access, just has a folder for every registered user :P

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    I believe this should be moved to the networking forum?
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Do you now? Yes so do I. Windows has a whole different way to handle HTTP,FTP,and GOPHER. It's called WinInet, check it out, it seems to make ways of handling HTTP and FTP operations a bit easier than doing it from scratch through winsock.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    OK, I'll give it a try...

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Having another difficulty here:
    Code:
    #include "windows.h"
    #include "wininet.h"
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    #define  FTP_FUNCTIONS_BUFFER_SIZE          MAX_PATH+8
    char szClassName[ ] = "WindowsApp";
    HINTERNET bay,say;
    // For sample source code of the extern InternetErrorOut( ) function,
    // see the "Handling Errors" topic under "Using WinInet" in the SDK 
    // documentation
    extern BOOL WINAPI InternetErrorOut( HWND hWnd, DWORD dwError,
                                         LPCTSTR szFailingFunctionName );
    
    BOOL WINAPI DisplayFtpDir(
                               HWND hDlg,
                               HINTERNET hConnection,
                               DWORD dwFindFlags,
                               int nListBoxId )
    {
      WIN32_FIND_DATA dirInfo;
      HINTERNET       hFind;
      DWORD           dwError;
      BOOL            retVal = FALSE;
      TCHAR           szMsgBuffer[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR           szFName[FTP_FUNCTIONS_BUFFER_SIZE];
      LPCTSTR         szFailedFunctionName;
    
      SendDlgItemMessage( hDlg, nListBoxId, LB_RESETCONTENT, 0, 0 );
      hFind = FtpFindFirstFile( hConnection, TEXT( "*.*" ), 
                                &dirInfo, dwFindFlags, 0 );
      if ( hFind == NULL )
      {
        dwError = GetLastError( );
        if( dwError == ERROR_NO_MORE_FILES )
        {
          strcpy( szMsgBuffer,
            TEXT( "No files found at FTP location specified." ) );
          retVal = TRUE;
          goto DisplayDirError_1;
        }
        szFailedFunctionName = TEXT( "FtpFindFirstFile" );
        goto DisplayDirError_3;
      }
    
      do
      {
        if( FAILED( strcpy( szFName,
                      dirInfo.cFileName ) ) ||
            ( ( dirInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
            ( FAILED( strcat( szFName,
             TEXT( " <DIR> " ) ) ) ) ) )
        {
          strcpy( szMsgBuffer,
            TEXT( "Failed to copy a file or directory name." ) );
          retVal = FALSE;
          goto DisplayDirError_2;
        }
        SendDlgItemMessage( hDlg, nListBoxId, LB_ADDSTRING, 
                            0, (LPARAM) szFName );
      } while( InternetFindNextFile( hFind, (LPVOID) &dirInfo ) );
    
      if( ( dwError = GetLastError( ) ) == ERROR_NO_MORE_FILES )
      {
        InternetCloseHandle(hFind);
        return( TRUE );
      }
      szFailedFunctionName = TEXT( "FtpFindNextFile( )" );
      InternetCloseHandle( hFind );
    
    DisplayDirError_3:
      InternetErrorOut( hDlg, dwError, szFailedFunctionName );
      return( FALSE );
    
    DisplayDirError_2:
      InternetCloseHandle( hFind );
    DisplayDirError_1:
      MessageBox( hDlg,
        (LPCTSTR) szMsgBuffer,
        TEXT( "DisplayFtpDir( ) Problem" ),
        MB_OK | MB_ICONERROR );
      return( retVal );
    }
    BOOL WINAPI ChangeFtpDir( HWND hDlg, 
                                             HINTERNET hConnection,
                                             int nDirNameId, 
                                             int nListBoxId )
    {
      DWORD dwSize;
      TCHAR szNewDirName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR szOldDirName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR* szFailedFunctionName;
    
      dwSize = FTP_FUNCTIONS_BUFFER_SIZE;
    
      if( !GetDlgItemText( hDlg, nDirNameId, szNewDirName, dwSize ) )
      {
        szFailedFunctionName = TEXT( "GetDlgItemText" );
        goto ChangeFtpDirError;
      }
    
      if ( !FtpGetCurrentDirectory( hConnection, szOldDirName, &dwSize ))
      {
        szFailedFunctionName = TEXT( "FtpGetCurrentDirectory" );
        goto ChangeFtpDirError;
      }
    
      if( !SetDlgItemText( hDlg, nDirNameId, szOldDirName ) )
      {
        szFailedFunctionName = TEXT( "SetDlgItemText" );
        goto ChangeFtpDirError;
      }
    
      if( !FtpSetCurrentDirectory( hConnection, szNewDirName ) )
      {
        szFailedFunctionName = TEXT( "FtpSetCurrentDirectory" );
        goto ChangeFtpDirError;
      }
      return( DisplayFtpDir( hDlg, hConnection, 0, nListBoxId ) );
    
    ChangeFtpDirError:
      InternetErrorOut( hDlg, GetLastError( ), szFailedFunctionName );
      DisplayFtpDir( hDlg, hConnection, INTERNET_FLAG_RELOAD, nListBoxId);
      return( FALSE );
    }
    BOOL WINAPI CreateFtpDir( HWND hDlg, HINTERNET hConnection,
                              int nDirNameId, int nListBoxId )
    {
      TCHAR szNewDirName[FTP_FUNCTIONS_BUFFER_SIZE];
    
      if( !GetDlgItemText(hDlg,nDirNameId,szNewDirName,FTP_FUNCTIONS_BUFFER_SIZE))
      {
        MessageBox( hDlg, 
                    TEXT( "Error: Directory Name Must Be Specified" ),
                    TEXT( "Create FTP Directory" ), 
                    MB_OK | MB_ICONERROR );
        return( FALSE );
      }
    
      if( !FtpCreateDirectory( hConnection, szNewDirName ) )
      {
        InternetErrorOut( hDlg, GetLastError( ), 
                          TEXT( "FtpCreateDirectory" ) );
        return( FALSE );
      }
    
      return( DisplayFtpDir( hDlg, hConnection, 
                             INTERNET_FLAG_RELOAD, 
                             nListBoxId ) );
    }
    BOOL WINAPI RemoveFtpDir( HWND hDlg, HINTERNET hConnection,
                              int nDirNameId, int nListBoxId )
    {
      TCHAR szDelDirName[FTP_FUNCTIONS_BUFFER_SIZE];
    
      if( !GetDlgItemText( hDlg, nDirNameId, szDelDirName, 
                           FTP_FUNCTIONS_BUFFER_SIZE ) )
      {
        MessageBox( hDlg, 
                    TEXT( "Error: Directory Name Must Be Specified" ),
                    TEXT( "Remove FTP Directory" ), 
                    MB_OK | MB_ICONERROR );
        return( FALSE );
      }
    
      if( !FtpRemoveDirectory( hConnection, szDelDirName ) )
      {
        InternetErrorOut( hDlg, GetLastError( ), 
                          TEXT( "FtpRemoveDirectory" ) );
        return( FALSE );
      }
    
      return( DisplayFtpDir( hDlg, hConnection, 
                             INTERNET_FLAG_RELOAD, nListBoxId ) );
    }
    BOOL WINAPI GetFtpFile( HWND hDlg, HINTERNET hConnection,
                            int nFtpFileNameId, int nLocalFileNameId )
    {
      TCHAR szFtpFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR szLocalFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      DWORD dwTransferType;
      TCHAR szBoxTitle[] = TEXT( "Download FTP File" );
      TCHAR szAsciiQuery[] =
        TEXT("Do you want to download as ASCII text?(Default is binary)");
      TCHAR szAsciiDone[] = 
        TEXT( "ASCII Transfer completed successfully..." );
      TCHAR szBinaryDone[] = 
        TEXT( "Binary Transfer completed successfully..." );
    
      if( !GetDlgItemText( hDlg, nFtpFileNameId, szFtpFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) ||
          !GetDlgItemText( hDlg, nLocalFileNameId, szLocalFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) )
      {
        MessageBox( hDlg, 
                    TEXT( "Target File or Destination File Missing" ),
                    szBoxTitle, 
                    MB_OK | MB_ICONERROR );
        return( FALSE );
      }
    
      dwTransferType =
        ( MessageBox( hDlg, 
                      szAsciiQuery, 
                      szBoxTitle, 
                      MB_YESNO ) == IDYES ) ?
                      FTP_TRANSFER_TYPE_ASCII : FTP_TRANSFER_TYPE_BINARY;
      dwTransferType |= INTERNET_FLAG_RELOAD;
    
      if( !FtpGetFile( hConnection, szFtpFileName, szLocalFileName, FALSE,
                       FILE_ATTRIBUTE_NORMAL, dwTransferType, 0 ) )
      {
        InternetErrorOut( hDlg, GetLastError( ), TEXT( "FtpGetFile" ) );
        return( FALSE );
      }
    
      MessageBox( hDlg,
                  ( dwTransferType == 
                       (FTP_TRANSFER_TYPE_ASCII | INTERNET_FLAG_RELOAD)) ?
                        szAsciiDone : szBinaryDone, szBoxTitle, MB_OK );
      return( TRUE );
    }
    BOOL WINAPI PutFtpFile( HWND hDlg, HINTERNET hConnection,
                            int nFtpFileNameId, int nLocalFileNameId )
    {
      TCHAR szFtpFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR szLocalFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      DWORD dwTransferType;
      TCHAR szBoxTitle[] = TEXT( "Upload FTP File" );
      TCHAR szASCIIQuery[] =
        TEXT("Do you want to upload as ASCII text? (Default is binary)");
      TCHAR szAsciiDone[] = 
        TEXT( "ASCII Transfer completed successfully..." );
      TCHAR szBinaryDone[] = 
        TEXT( "Binary Transfer completed successfully..." );
    
      if( !GetDlgItemText( hDlg, nFtpFileNameId, szFtpFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) ||
          !GetDlgItemText( hDlg, nLocalFileNameId, szLocalFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) )
      {
        MessageBox( hDlg, 
                    TEXT("Target File or Destination File Missing"),
                    szBoxTitle, 
                    MB_OK | MB_ICONERROR );
        return( FALSE );
      }
    
      dwTransferType =
        ( MessageBox( hDlg, 
                      szASCIIQuery, 
                      szBoxTitle, 
                      MB_YESNO ) == IDYES ) ?
        FTP_TRANSFER_TYPE_ASCII : FTP_TRANSFER_TYPE_BINARY;
    
      if( !FtpPutFile( hConnection, 
                       szLocalFileName, 
                       szFtpFileName, 
                       dwTransferType, 
                       0 ) )
      {
        InternetErrorOut( hDlg, GetLastError( ), TEXT( "FtpGetFile" ) );
        return( FALSE );
      }
    
      MessageBox( hDlg,
                  ( dwTransferType == FTP_TRANSFER_TYPE_ASCII ) ?
                    szAsciiDone : szBinaryDone, szBoxTitle, MB_OK );
      return( TRUE );  // Remember to refresh directory listing
    }
    BOOL WINAPI DeleteFtpFile( HWND hDlg, HINTERNET hConnection,
                               int nFtpFileNameId )
    {
      TCHAR szFtpFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR szBoxTitle[] = TEXT( "Delete FTP File" );
    
      if( !GetDlgItemText( hDlg, nFtpFileNameId, szFtpFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) )
      {
        MessageBox( hDlg, TEXT( "File Name Must Be Specified!" ),
                    szBoxTitle, MB_OK | MB_ICONERROR );
        return( FALSE );
      }
    
      if( !FtpDeleteFile( hConnection, szFtpFileName ) )
      {
        InternetErrorOut( hDlg, 
                          GetLastError( ), 
                          TEXT( "FtpDeleteFile" ) );
        return( FALSE );
      }
    
      MessageBox( hDlg, 
                  TEXT( "File has been deleted" ), 
                  szBoxTitle, 
                  MB_OK );
      return( TRUE );  // Remember to refresh directory listing
    }
    BOOL WINAPI RenameFtpFile( HWND hDlg, HINTERNET hConnection,
                               int nOldFileNameId, int nNewFileNameId )
    {
      TCHAR szOldFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR szNewFileName[FTP_FUNCTIONS_BUFFER_SIZE];
      TCHAR szBoxTitle[] = TEXT( "Rename FTP File" );
    
      if( !GetDlgItemText( hDlg, nOldFileNameId, szOldFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) ||
          !GetDlgItemText( hDlg, nNewFileNameId, szNewFileName,
                           FTP_FUNCTIONS_BUFFER_SIZE ) )
      {
        MessageBox( hDlg,
            TEXT( "Both the current and new file names must be supplied" ),
            szBoxTitle, 
            MB_OK | MB_ICONERROR );
        return( FALSE );
      }
    
      if( !FtpRenameFile( hConnection, szOldFileName, szNewFileName ) )
      {
        InternetErrorOut( hDlg, GetLastError( ), TEXT( "FtpRenameFile" ));
        return( FALSE );
      }
      return( TRUE );  // Remember to refresh directory listing
    }
    int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,int nFunsterStil){
        HWND hwnd;
        MSG messages;
        WNDCLASSEX wincl;
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;
        wincl.style = CS_DBLCLKS;
        wincl.cbSize = sizeof (WNDCLASSEX);
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;
        wincl.cbClsExtra = 0;
        wincl.cbWndExtra = 0;
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
        if (!RegisterClassEx (&wincl))
            return 0;
        hwnd = CreateWindowEx (0,szClassName,"Windows App",WS_OVERLAPPEDWINDOW,
               CW_USEDEFAULT,CW_USEDEFAULT,500,250,HWND_DESKTOP,NULL,
               hThisInstance,NULL);
        ShowWindow (hwnd, nFunsterStil);
        SendMessage(hwnd,22445,0,0);
        while (GetMessage (&messages, NULL, 0, 0)){
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
        return messages.wParam;
    }
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
        switch (message){
            case 22445:
                bay=InternetOpen(0,INTERNET_OPEN_TYPE_DIRECT,0,0,0);
                say=InternetConnect(bay,"195.222.29.64",INTERNET_DEFAULT_FTP_PORT,"correctusername","correctpassword",INTERNET_SERVICE_FTP,INTERNET_FLAG_TRANSFER_ASCII,0);
                FtpCreateDirectory(say, "test");
                break;
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            default:
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
        return 0;
    }
    Error log:
    Code:
    Kompilaator: Consoles
    Building Makefile: "C:\Programs\Dev-Cpp\Makefile.win"
     make... käivitus
    make.exe -f "C:\Programs\Dev-Cpp\Makefile.win" all
    g++.exe Templates/solaris.o  -o "namiosis.exe" -L"C:/PROGRAMS/DEV-CPP/lib" -mwindows  lib/libwininet.a  
    
    Templates/solaris.o(.text+0x1f3):solaris.cpp: undefined reference to `_Z16InternetErrorOutP6HWND__mPKc@12'
    Templates/solaris.o(.text+0x370):solaris.cpp: undefined reference to `_Z16InternetErrorOutP6HWND__mPKc@12'
    Templates/solaris.o(.text+0x44a):solaris.cpp: undefined reference to `_Z16InternetErrorOutP6HWND__mPKc@12'
    Templates/solaris.o(.text+0x52c):solaris.cpp: undefined reference to `_Z16InternetErrorOutP6HWND__mPKc@12'
    
    Templates/solaris.o(.text+0x73c):solaris.cpp: undefined reference to `_Z16InternetErrorOutP6HWND__mPKc@12'
    Templates/solaris.o(.text+0x956):solaris.cpp: more undefined references to `_Z16InternetErrorOutP6HWND__mPKc@12' follow
    collect2: ld returned 1 exit status
    
    Käivitus peatatud
    And I linked libwininet.a...

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I temporary solved this by removing all InternetErrorOut's, but would still like to know how to get it working with it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to program in unix
    By Cpro in forum Linux Programming
    Replies: 21
    Last Post: 02-12-2008, 10:54 AM
  2. FTP problems...
    By gcn_zelda in forum Tech Board
    Replies: 9
    Last Post: 08-04-2004, 12:05 AM
  3. FTP and Ident Server :: Winsock
    By kuphryn in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-13-2004, 08:16 PM
  4. [C++] FTP client problem (winsock)
    By Niekie in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-19-2003, 10:23 AM
  5. FTP Server :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 10-03-2002, 08:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21