Help with python inside C

This is a discussion on Help with python inside C within the C Programming forums, part of the General Programming Boards category; I wrote a simple ftp uploader with python, because ftplib is a very simple library, and i wanted to use ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    12

    Help with python inside C

    I wrote a simple ftp uploader with python, because ftplib is a very simple library, and i wanted to use this script in C but i have no idea, how to do this.
    Can you help me? Or can you suggest me an ftp library to use directly on C?
    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Quote Originally Posted by nicauron
    Or can you suggest me an ftp library to use directly on C?
    Try learning from Beej's Guide to Network Programming.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Or if you are on Windows, you can use it's built in library...

    FTP Sessions (Windows)

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    If you want to use the script you have you can either call it as an external process (using system, ShellExecute, etc...) or look to the python/C api - 5. Embedding Python in Another Application — Python v2.7.2 documentation

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    Quote Originally Posted by CommonTater View Post
    Or if you are on Windows, you can use it's built in library...

    FTP Sessions (Windows)
    I tried to use this library but i found some errors
    Code:
    int SendFTP() {
        
        
        HINTERNET hInternet;
        HINTERNET hFtpSession;
        hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
        hFtpSession = InternetConnect(hInternet,serverftp , INTERNET_DEFAULT_FTP_PORT,user, password, INTERNET_SERVICE_FTP, 0, 0);
        if(FtpPutFile(hFtpSession,file, namefile, FTP_TRANSFER_TYPE_BINARY,0) == TRUE){
                                   printf("File Sent! ");
                                   
                                   }
                                   
         else{
              printf("Sending Failed..");
              }
         InternetCloseHandle(hFtpSession);
         InternetCloseHandle(hInternet);
    }
    Dev C++ gave me this response
    : In function `SendFTP':
    undefined reference to `InternetOpenA@20'
    undefined reference to `InternetConnectA@32'
    undefined reference to `FtpPutFileA@20'
    undefined reference to `InternetCloseHandle@4'
    undefined reference to `InternetCloseHandle@4'
    collect2: ld returned 1 exit status

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You are missing an #include, have not told the linker about the library, or the library is not in minGW's default path.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    It looks like you didn't include wininet.lib in your linker's list.

    Also DevC++ is outdated and abandoned. It is entirely likely that it's missing several of the newer libraries...

    If you are doing C-99 only (no C++) you should probably update to Pelles C (free, available in both x86 and x64 flavours, resource editors included and the best help file I've ever seen)

    If you are doing C-89 and C++ you most likely want to use Code::Blocks with MinGW (C and C++, x86 only, no resource editors, free)

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    I'm using Dev-C++ and i made #include <wininet.h>
    So what is the problem??

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    2,773
    Quote Originally Posted by CommonTater View Post
    It looks like you didn't include wininet.lib in your linker's list.
    You need to tell the compiler to link to the needed library; likely wininet.lib or wininet.a.

    Tim S.

  10. #10
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Quote Originally Posted by nicauron View Post
    I'm using Dev-C++ and i made #include <wininet.h>
    So what is the problem??
    CommonTater told you right here:

    Quote Originally Posted by CommonTater View Post
    It looks like you didn't include wininet.lib in your linker's list.
    The header file just tells the compiler about the functions (name, return type, parameter types and count), it doesn't actually provide the implementations (i.e. there's no code). For that you need to tell the linker where to find the wininet.lib functions. But few of us can tell you where to set that up, since as Tater mentioned, Dev-C++ is outdated and abandoned, so few here use it.

  11. #11
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    I'm sorry but i don't know how to do it? Can you explain to me? Now I have installed Pelles C
    Last edited by nicauron; 07-06-2011 at 11:38 AM.

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nicauron View Post
    I'm sorry but i don't know how to do it? Can you explain to me? Now I have installed Pelles C
    In Project->Options->Folders->Library add the path to the folder the library is in.
    In Project->Options->Linker add the library name to the list.

  13. #13
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    The folder Path was already charged, and i added the library wininet.lib to the linkers but i already have the same problem.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nicauron View Post
    The folder Path was already charged, and i added the library wininet.lib to the linkers but i already have the same problem.
    If you're adding wininet.lib that's already on the default Pelles C search paths.

    Did you enable Microsoft Extensions in your Project->Options?

    Also if you're using MS library functions you need to set the calling protocal to STDCALL, on the same page.

    It might help if you posted the new error messages...
    Last edited by CommonTater; 07-06-2011 at 01:24 PM.

  15. #15
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    it's so weird, i made what you said and now the error changed, now the compiler found some errors in a function that Dev-C++ hadn't found, because the function worked!!
    These are the errors:

    warning #2027: Missing prototype for 'kp'.
    warning #2027: Missing prototype for 'kp'.
    warning #2027: Missing prototype for 'sleep'.
    warning #2027: Missing prototype for 'SendFTP'.
    warning #2096: Missing return value.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-13-2010, 04:14 PM
  2. python c api
    By ralu. in forum C Programming
    Replies: 0
    Last Post: 03-01-2009, 01:19 PM
  3. Python
    By mart_man00 in forum Tech Board
    Replies: 7
    Last Post: 10-06-2003, 08:24 AM
  4. anyone here knows Python ?
    By black in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 09-11-2002, 09:49 AM
  5. Python
    By Xterria in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-05-2002, 05:08 PM

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