[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Net::SFTP, copying directory recursively

Manish Sapariya

5/16/2007 4:49:00 PM

Hi,
I am trying to copy a remote directroy recursively using Net::sftp.

I could not find any direct api given by this module and decided to
copy the entire directory file by file.

However i am not able to figure out, how to tell between file or directory.

I am trying to follow simple method,

for every file in directory
if file is direcory
create directory
else
get/put directory
end

However I am not able to find out any method to figure out the type of
file on remote machine.

Any ideas?
Thanks and Regards,
Manish



12 Answers

andy

6/25/2007 8:07:00 PM

0

Manish Sapariya schrieb:
> Hi,
> I am trying to copy a remote directroy recursively using Net::sftp.
>
> I could not find any direct api given by this module and decided to
> copy the entire directory file by file.
>
> However i am not able to figure out, how to tell between file or directory.
>
> I am trying to follow simple method,
>
> for every file in directory
> if file is direcory
> create directory
> else
> get/put directory
> end
>
> However I am not able to find out any method to figure out the type of
> file on remote machine.
>
> Any ideas?
> Thanks and Regards,
> Manish
>
>
>
>


I just had this same problem, while I didn't solve your precise issue;
the following code will recursively download the contents of a folder.

It's rather crude, if anyone has a refactor suggestion I'm quite open to
hear it.


#################################################
require 'rubygems'
require 'net/sftp'

def open_or_get_all(sftp, open_dir, local_dir)
handle = sftp.opendir(open_dir)
items = sftp.readdir(handle)
items.each do |item|
if item.filename != '.' && item.filename != '..'
if item.longname[0...1] == 'd'
# mkdir locally
Dir.mkdir(local_dir + item.filename, 0777)
# open dir and download all
open_or_get_all(sftp, open_dir + item.filename + '/', local_dir
+ item.filename + '/')
else
#puts local_dir+item.filename
#puts open_dir+item.filename
sftp.get_file open_dir+item.filename, local_dir+item.filename
end
end
end
sftp.close_handle(handle)
end

Net::SFTP.start('ext_server', 'user_name', 'password') do |sftp|
open_or_get_all(sftp, "/home/user_name/dir_to_dnld/", "/lcl_dir/")
end


#################################################

maybe that will save someone else a few minutes...

John Doe

2/7/2014 10:28:00 PM

0

On Fri, 7 Feb 2014 14:53:33 -0800 (PST), Werner <whetzner@mac.com>
wrote:

>Would there be a Beethoven were it not for royal supporters? Tourists to Europe flock to things built by royals. They don't flock to things built by socialists, welfare people, or The Public. It is said King Ludwig of Bavaria was drowned for his extravagance. But Bavarians have been cashing in on his castles since.


You are so full of s.

Of course there'd be a Beethoven without royals. He didn't have
them when he was becoming Beethoven.

You can't congratulate the "aristocracy" for being the only people
to build luxury buildings when they were the only people who
could afford to do so. I repeat, you are so full of s. I'm not sure
if you realize that, though I don't see how you could miss it.





Werner

2/7/2014 11:38:00 PM

0

I'm still searching for something created by The Public. You probably see such everywhere. So,which of us is full of shit?

John Doe

2/7/2014 11:50:00 PM

0

On Fri, 7 Feb 2014 15:37:44 -0800 (PST), Werner <whetzner@mac.com>




>I'm still searching for something created by The Public. You probably see such everywhere. So,which of us is full of shit?


How about the United States of America? And almost
no great poetry or music or painting was created by the
"aristocracy". Of course, if something costs a million
dollars to build, it will be financed by the aristocracy and
have their names on it, though what's fine about it is
almost always the work of other people.

I'm thinking you must just be bored and joking around,
which makes me wonder how serious you really are about
all this "Libertarian" stuff too.

Werner

2/8/2014 2:57:00 AM

0

People exist, rumple. The Public is only in your imagination. If The Public actually existed, which it doesn't, King Ludwig would be as much The Public as Beehoven.

John Doe

2/8/2014 3:56:00 AM

0

On Fri, 7 Feb 2014 18:56:55 -0800 (PST), Werner <whetzner@mac.com>
wrote:

>People exist, rumple. The Public is only in your imagination. If The Public actually existed, which it doesn't, King Ludwig would be as much The Public as Beehoven.


Your argument fell flat on its face (if you still remember
what it was), so you trot out one of your tropes as a
non-sequitur, just to keep making noise. I guess that's
how you stay a "believer".






islander

2/9/2014 3:38:00 PM

0

On 2/7/2014 7:55 PM, Rumpelstiltskin wrote:
> On Fri, 7 Feb 2014 18:56:55 -0800 (PST), Werner <whetzner@mac.com>
> wrote:
>
>> People exist, rumple. The Public is only in your imagination. If The Public actually existed, which it doesn't, King Ludwig would be as much The Public as Beehoven.
>
>
> Your argument fell flat on its face (if you still remember
> what it was), so you trot out one of your tropes as a
> non-sequitur, just to keep making noise. I guess that's
> how you stay a "believer".
>

Ever wonder why Werner maintains his own website? He used to be
associated with the Capital District Libertarian Party in Albany NY, but
his views appear to be too extreme even for them. They don't even
acknowledge his website from theirs. Sad!

John Doe

2/10/2014 2:45:00 AM

0

On Sun, 09 Feb 2014 07:37:47 -0800, islander <none@priracy.com> wrote:

>On 2/7/2014 7:55 PM, Rumpelstiltskin wrote:
>> On Fri, 7 Feb 2014 18:56:55 -0800 (PST), Werner <whetzner@mac.com>
>> wrote:
>>
>>> People exist, rumple. The Public is only in your imagination. If The Public actually existed, which it doesn't, King Ludwig would be as much The Public as Beehoven.
>>
>>
>> Your argument fell flat on its face (if you still remember
>> what it was), so you trot out one of your tropes as a
>> non-sequitur, just to keep making noise. I guess that's
>> how you stay a "believer".
>>
>
>Ever wonder why Werner maintains his own website? He used to be
>associated with the Capital District Libertarian Party in Albany NY, but
>his views appear to be too extreme even for them. They don't even
>acknowledge his website from theirs. Sad!


I've not seen anybody here comment on Werner's links (though
I do have a lot of right-wingers killfiled and about five of them
nuked). It must take a lot of dedication to write a set of tracts and
put them out on the web, though. Sometimes I think Werner can't
possibly be serious, as in maintaining that there is no "the public",
but I guess he is. His argumentation in this thread has been an
illustration of how specious the basis of his thinking can be, IMO.



Werner

2/10/2014 2:55:00 AM

0

I'm still searching for something created by The Public. You probably see such everywhere. So,which of us is full of shit?

Werner

2/10/2014 3:10:00 AM

0

I'm still searching for something created by The Public. You probably see such everywhere. So,which of us is full of shit?