Solved

how to use ruby connect ftps?

Posted on 2006-11-05
11
895 Views
Last Modified: 2012-06-27
i would like to know about connecting to ftps by using ruby.
do you have any suggestion or example ?
thanks in advance.
0
Comment
Question by:mgd_expert
  • 6
  • 5
11 Comments
 
LVL 24

Expert Comment

by:fridom
ID: 17880642
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
 

Author Comment

by:mgd_expert
ID: 17895045
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
 
LVL 24

Expert Comment

by:fridom
ID: 17896066
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:mgd_expert
ID: 17903620
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
 
LVL 24

Expert Comment

by:fridom
ID: 17904034
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
 

Author Comment

by:mgd_expert
ID: 17904743
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
 

Author Comment

by:mgd_expert
ID: 17904835
thank you very much . i will try
http://rubyforge.org/projects/ftpfxp/

regards
Sayan
0
 
LVL 24

Accepted Solution

by:
fridom earned 200 total points
ID: 17920312
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
 

Author Comment

by:mgd_expert
ID: 17935569
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
 
LVL 24

Expert Comment

by:fridom
ID: 17936329
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
 

Author Comment

by:mgd_expert
ID: 17936389
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
static class 3 69
fix34  challenge 9 118
split53 challenge 7 96
Change to event 1 112
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question