Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to use ruby connect ftps?

Posted on 2006-11-05
11
Medium Priority
?
918 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 600 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 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