FTP script won't transfer remote files to local computer

1,438

Before the mget command add a line that says

prompt
Share:
1,438
user422005
Author by

user422005

Updated on September 17, 2022

Comments

  • user422005
    user422005 over 1 year

    I have a C library with several datatypes which I have wrapped with Python and ctypes - works very well! In C I have the following (schematic) code:

    typedef struct type1_struct type1_t;
    typedef struct type2_struct type2_t;  
    
    void some_function( type1_t *t1 , type2_t *t2) {  
      if (t2 == NULL) {  
         // Do whatever  
      } else {  
         // 
      }
    }  
    

    The main point in this code is that some_function() can take NULL as value for the t2 argument. In Python the type1_t and type2_t types are wrapped with classes Type1 and Type2 using the from_param() method:

    Class Type1:
       def from_param(self):
           return self.c_ptr
    
    
       def call_some_func(self , arg2 = None):
           # This fails when the python/ctypes tries to
           # lookup the from_param() method and arg2 is None. 
           cfunc_some_function( self , arg2 )     
    
    
    lib_handle = ctypes.CDLL( lib )
    cfunc_some_function = getattr( lib_handle , "some_function")
    cfunc_some_function.argtypes = [Type1 , Type2]
    

    So the cfunc_some_function function is initialized to take a Type1 and Type2 instance as arguments, the ctypes layer will then call the from_param() methods of the two input arguments; however I would like the 'call_some_func()' method of the Type1 class to accept None for the arg2 argument, but then ctypes tries to call the from_param() method of the None object - which obviously fails.

    So - I guess my question is: Is it possible to get the ctypes function call code to just pass NULL when it gets a None input argument?

    Joakim

  • Richard
    Richard over 14 years
    now this goes thru all files on remote folder, but keeps saying "port command successful. no such file" ... all files are there though ... any ideas?
  • Richard
    Richard over 14 years
    same results ... loops thru all the files in the folder, and keeps saying "no such file" but all the files are there ... i use the same credentials as i use for GUI ftp access, so permissions should not be the issue ... any ideas?
  • Richard
    Richard over 14 years
    didn't solve the issue but helped me get starter, thanx
  • Stewart Robinson
    Stewart Robinson over 14 years
    did you fix why the files weren't coming down?
  • user422005
    user422005 almost 13 years
    OK; that was interesting. I have ~ 15 cases of from_param() as a instance method, and that has worked nicely for me (except this instance is None problem). I did as you suggested and it worked nicely. Thanks!
  • Duncan
    Duncan almost 13 years
    I think it will work in most cases: Type.method(obj) and obj.method() are interchangeable when obj is an instance of Type, but ctypes can also call Type.method(obj) when obj is a different type such a None and that's what you've run into.
  • Duncan
    Duncan almost 13 years
    @eryksun thanks: corrected. That's why I always write 'untested' when I can't test a code sample.