Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 925
  • Last Modified:

how to use ruby connect ftps?

i would like to know about connecting to ftps by using ruby.
do you have any suggestion or example ?
thanks in advance.
0
mgd_expert
Asked:
mgd_expert
  • 6
  • 5
1 Solution
 
fridomCommented:
There are  few options for that avialable.
sftp library
http://net-ssh.rubyforge.org/sftp/faq.html

and the ruby libcurl binding will work also, You can get it from:
http://www.d1.dion.ne.jp/~matuyuki/ruby.html

Regards
Friedrich
0
 
mgd_expertAuthor Commented:
Thank you Friedrich
sftp library
http://net-ssh.rubyforge.org/sftp/faq.html
This link is about sftp (SSH FTP) not FTPS(SSL) .


And the 2nd link i think it's very good
http://www.d1.dion.ne.jp/~matuyuki/ruby.html
but i have no idia how to include this library into ruby.
i extract rbCurl-0.0.2a0.tgz and i got
        api.def
        auto_defs.inc
        auto_funcs.inc
        example.rb
        extconf.rb
        gen_api.rb
        init.c
        README
        template.rb
        TODO
These files didn't tell how to add these files into ruby. Just have example file but i have to include some library to ruby first. Does anyone can tell me how to add these files into ruby?
   




0
 
fridomCommented:
Check the README. the usual way of making it is likes this:
ruby extconf.rb

make
make install

You may found that you have to add
#define TRUE 1
#define FALSE (! TRUE)

to the generated C files and maybe add a CURL_
in front of the globals

Regards
Friedrich
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mgd_expertAuthor Commented:
This is what you mean . In init.c file
i changed from

#include <ruby.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

typedef struct _rbCurl  rbCurl;
typedef struct _pFILE   pFILE;

to


#include <ruby.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#define TRUE 1
#define FALSE (! TRUE)
typedef struct CURL_rbCurl  rbCurl;
typedef struct CURL_pFILE   pFILE;


>> ruby extconf.rb
i got result "creating Makefile"


when i
>> make  
i got

  gcc -fPIC -Wall -g -O2  -fPIC  -I. -I/usr/lib/ruby/1.8/i486-linux -I/usr/lib/ruby/1.8/i486-linux -I.   -c init.c
In file included from init.c:43:
auto_funcs.inc: In function ‘set_url’:
auto_funcs.inc:11: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:19: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_port’:
auto_funcs.inc:30: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_proxy’:
auto_funcs.inc:44: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:52: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_userpwd’:
auto_funcs.inc:66: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:74: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_proxyuserpwd’:
auto_funcs.inc:88: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:96: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_range’:
auto_funcs.inc:110: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:118: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_timeout’:
auto_funcs.inc:129: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_postfields’:
auto_funcs.inc:143: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:146: error: dereferencing pointer to incomplete type
auto_funcs.inc:150: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_referer’:
auto_funcs.inc:165: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:173: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_ftpport’:
auto_funcs.inc:187: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:195: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_useragent’:
auto_funcs.inc:209: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:217: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_low_speed_limit’:
auto_funcs.inc:228: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_low_speed_time’:
auto_funcs.inc:239: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_resume_from’:
auto_funcs.inc:250: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_cookie’:
auto_funcs.inc:264: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc:272: error: dereferencing pointer to incomplete type
auto_funcs.inc: In function ‘set_httpheader’:

i don't understand with these errors.
do you have any suggestion?
Regards
Sayan
0
 
fridomCommented:
Ah I see, and well it seems it was that my writings were unclear.

typedef struct CURL_rbCurl  rbCurl;
typedef struct CURL_pFILE   pFILE;

surely not

drop the CURL in front of it:
The TRUE, FALSE stuff seems to be ok. I have just guarded it like this:
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (! FALSE)
#endif

And the constants I meant can be found near the button of the init.c file the look like this here:
 rb_define_const(cCurl, "CURL_TIMECOND_NONE", INT2FIX(CURL_TIMECOND_NONE));
   rb_define_const(cCurl, "CURL_TIMECOND_IFMODSINCE", INT2FIX(CURL_TIMECOND_IFMODSINCE));
   rb_define_const(cCurl, "CURLTIMECOND_IFUNMODSINCE", INT2FIX(CURL_TIMECOND_IFUNMODSINCE));
   rb_define_const(cCurl, "CURL_TIMECOND_LASTMOD", INT2FIX(CURL_TIMECOND_LASTMOD));


Regards
Friedrich
0
 
mgd_expertAuthor Commented:
i changed from

>>>rb_define_const(cCurl, "TIMECOND_NONE", INT2FIX(TIMECOND_NONE));
   rb_define_const(cCurl, "TIMECOND_IFMODSINCE", INT2FIX(TIMECOND_IFMODSINCE));
   rb_define_const(cCurl, "TIMECOND_IFUNMODSINCE", INT2FIX(TIMECOND_IFUNMODSINCE));
   rb_define_const(cCurl, "TIMECOND_LASTMOD", INT2FIX(TIMECOND_LASTMOD));

   rb_define_const(cCurl, "HTTP_VERSION_NONE", INT2FIX(CURL_HTTP_VERSION_NONE));
   rb_define_const(cCurl, "HTTP_VERSION_1_0", INT2FIX(CURL_HTTP_VERSION_1_0));
   rb_define_const(cCurl, "HTTP_VERSION_1_1", INT2FIX(CURL_HTTP_VERSION_1_1));

   rb_define_const(cCurl, "SSLVERSION_DEFAULT", INT2FIX(CURL_SSLVERSION_DEFAULT));
   rb_define_const(cCurl, "SSLVERSION_TLSv1", INT2FIX(CURL_SSLVERSION_TLSv1));
   rb_define_const(cCurl, "SSLVERSION_SSLv2", INT2FIX(CURL_SSLVERSION_SSLv2));
   rb_define_const(cCurl, "SSLVERSION_SSLv3", INT2FIX(CURL_SSLVERSION_SSLv3));

to  
>>>>rb_define_const(cCurl, "CURL_TIMECOND_NONE", INT2FIX(CURL_TIMECOND_NONE));
   rb_define_const(cCurl, "CURL_TIMECOND_IFMODSINCE", INT2FIX(CURL_TIMECOND_IFMODSINCE));
   rb_define_const(cCurl, "CURL_TIMECOND_IFUNMODSINCE", INT2FIX(CURL_TIMECOND_IFUNMODSINCE));
   rb_define_const(cCurl, "CURL_TIMECOND_LASTMOD", INT2FIX(CURL_TIMECOND_LASTMOD));

   rb_define_const(cCurl, "CURL_HTTP_VERSION_NONE", INT2FIX(CURL_HTTP_VERSION_NONE));
   rb_define_const(cCurl, "CURL_HTTP_VERSION_1_0", INT2FIX(CURL_HTTP_VERSION_1_0));
   rb_define_const(cCurl, "CURL_HTTP_VERSION_1_1", INT2FIX(CURL_HTTP_VERSION_1_1));

   rb_define_const(cCurl, "CURL_SSLVERSION_DEFAULT", INT2FIX(CURL_SSLVERSION_DEFAULT));
   rb_define_const(cCurl, "CURL_SSLVERSION_TLSv1", INT2FIX(CURL_SSLVERSION_TLSv1));
   rb_define_const(cCurl, "CURL_SSLVERSION_SSLv2", INT2FIX(CURL_SSLVERSION_SSLv2));
   rb_define_const(cCurl, "CURL_SSLVERSION_SSLv3", INT2FIX(CURL_SSLVERSION_SSLv3));
}

i still got the sam error
>>>>
          gcc -fPIC -Wall -g -O2  -fPIC  -I. -I/usr/lib/ruby/1.8/i486-linux -I/usr/lib/ruby/1.8/i486-linux -I.   -c init.c
In file included from init.c:43:
auto_funcs.inc: In function ‘set_url’:
auto_funcs.inc:11: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_proxy’:
auto_funcs.inc:44: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_userpwd’:
auto_funcs.inc:66: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_proxyuserpwd’:
auto_funcs.inc:88: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_range’:
auto_funcs.inc:110: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_postfields’:
auto_funcs.inc:143: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_referer’:
auto_funcs.inc:165: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_ftpport’:
auto_funcs.inc:187: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_useragent’:
auto_funcs.inc:209: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_cookie’:
auto_funcs.inc:264: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_sslcert’:
auto_funcs.inc:308: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_sslcertpasswd’:
auto_funcs.inc:330: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_cookiefile’:
auto_funcs.inc:389: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_customrequest’:
auto_funcs.inc:444: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_interface’:
auto_funcs.inc:679: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_krb4level’:
auto_funcs.inc:701: warning: passing argument 2 of ‘rb_str2cstr’ from incompatible pointer type
auto_funcs.inc: In function ‘set_cainfo’:

Regards
Sayan
0
 
mgd_expertAuthor Commented:
thank you very much . i will try
http://rubyforge.org/projects/ftpfxp/

regards
Sayan
0
 
fridomCommented:
The warnings do not matter at all. You still should have  curl.so in the directory. However I've downloaded a version to:
http://www.q-software-solutions.de/~frido/curl.so.tgz 

Regards
Friedrich
0
 
mgd_expertAuthor Commented:
Now i can work with curl lib.

And i wrote code like this.

w = Curl.new
w.url = 'ftps://192.168.0.249/'              # edit here!
w.userpwd = 'anonymous:tsa@gmail.com'              # edit here!
w.port = 21
#w.quote = 'CWD tmp'
#w.quote = 'NLST P*"
#w.infile = 'TEST'                        # edit here!
#w.input_str = "test\nstrings\n"         # edit here!
#w.upload = true
w.verbose = true
w.perform
puts w.body_str


when i run i got

* About to connect() to 192.168.0.249 port 21
*   Trying 192.168.0.249... * connected
* Connected to 192.168.0.249 (192.168.0.249) port 21
* successfully set certificate verify locations:
*   CAfile: /usr/share/curl/curl-ca-bundle.crt
  CApath: none
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Closing connection #0
test_ftps.rb:24:in `perform': error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (RuntimeError)
        from test_ftps.rb:24


in /usr/share/curl/curl-ca-bindle.crt i append 192.168.0.249 certificate like this

-----BEGIN CERTIFICATE-----
      ********************
-----END CERTIFICATE-----

do you have an example about using rubylibcurl connect ftps?
and when i use
w.quote = 'CWD tmp'
w.quote = 'NLST P*"

i got

test_ftps.rb:18:in `quote=': can't convert Fixnum into String (TypeError)
        from test_ftps.rb:18
do you have any example about using quote in this lib?

regards
Sayan
0
 
fridomCommented:
I use it for connecting to an https server. And I have no ftps server available. The bug in your code with the quuote is the following:

w.quote = 'NLST P*"

You have to use the same separator on both ends of the string

w.quote  = 'NLST P*'
or
w.quote = "NLST P*"

Regards
Friedrich
0
 
mgd_expertAuthor Commented:
i changed to
w.quote = "CWD tmp"
w.quote = "NLST P*"
but i still got the same problem

test_ftps.rb:18:in `quote=': can't convert Fixnum into String (TypeError)
        from test_ftps.rb:18


regards
Sayan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now