fun_sftp 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/README.md +182 -0
- data/fun_sftp.gemspec +1 -0
- data/lib/fun_sftp/configuration.rb +43 -0
- data/lib/fun_sftp/download_callbacks.rb +23 -0
- data/lib/fun_sftp/upload_callbacks.rb +23 -0
- data/lib/fun_sftp/version.rb +1 -1
- data/lib/fun_sftp.rb +91 -26
- data/spec/fun_sftp/sftp_client_spec.rb +69 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/test1.txt +2 -0
- metadata +75 -65
- data/README.rdoc +0 -116
data/.rspec
ADDED
data/README.md
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/fun_sftp.png)](http://badge.fury.io/rb/fun_sftp)
|
2
|
+
|
3
|
+
FunSftp
|
4
|
+
=======
|
5
|
+
|
6
|
+
FunSftp is a ruby gem that provides a nice and easy to use wrapper for the Net::SFTP library.
|
7
|
+
|
8
|
+
Reference: [net-sftp](http://net-ssh.github.com/sftp/v2/api/index.html)
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'fun_sftp'
|
15
|
+
```
|
16
|
+
|
17
|
+
Usage
|
18
|
+
-----
|
19
|
+
|
20
|
+
Let's say you need to send a file or directory to a remote host. Well, you can upload it to the remote host via the following:
|
21
|
+
|
22
|
+
Setup the connection and specify a `source` directory if desired:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
include FunSftp
|
26
|
+
conn = SFTPClient.new(server, username, password)
|
27
|
+
conn.source = 'projects/awesome_project' #optional
|
28
|
+
```
|
29
|
+
|
30
|
+
Changing directories `chdir` and listing all files `ll` can be useful when working in a console. FunSftp now allows you to change your location on the remote host. This saves you from constantly entering long absolute paths.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
conn.chdir("projects")
|
34
|
+
# Changes Directory
|
35
|
+
# => "Current Path changed to => ./projects"
|
36
|
+
|
37
|
+
conn.ll
|
38
|
+
# Lists all files in current location
|
39
|
+
# => file1
|
40
|
+
# file2
|
41
|
+
# Directory1
|
42
|
+
# Directory2
|
43
|
+
|
44
|
+
conn.pwd
|
45
|
+
# Returns the current working directory
|
46
|
+
# => "./projects"
|
47
|
+
```
|
48
|
+
|
49
|
+
If you need to start from scratch then reset to the base path:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
conn.reset_path!
|
53
|
+
# => "Path Reset and set to => ."
|
54
|
+
```
|
55
|
+
|
56
|
+
Now, you can upload your file:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
conn.upload!("my_local_file_name.txt", "some_remote_directory/give_a_name.txt")
|
60
|
+
```
|
61
|
+
|
62
|
+
or directory
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
conn.upload!("my_awesome_local_directory", "desired_remote_directory_name")
|
66
|
+
```
|
67
|
+
|
68
|
+
That's it! Check the remote host to see that your file posted.
|
69
|
+
|
70
|
+
You can also download a remote file to your local machine:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
conn.download!("some_remote_directory/file_to_download_name.txt", "desired_local_name.txt")
|
74
|
+
```
|
75
|
+
|
76
|
+
or directory
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
conn.download!("some_remote_directory", "desired_local_directory_name")
|
80
|
+
```
|
81
|
+
|
82
|
+
Need to read a file on the remote host? Ah, it's no biggie...
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
conn.read("path/to/file_name.txt")
|
86
|
+
# => Hello World!
|
87
|
+
```
|
88
|
+
|
89
|
+
When investigating items on the remote host, these commands can be handy:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
conn.has_directory?("directory_name")
|
93
|
+
# returns true or false if the directory exists
|
94
|
+
|
95
|
+
conn.entries("directory_name")
|
96
|
+
# outputs a nice array of entries in the specified directory
|
97
|
+
# Pass true as a second argument if you would like to see '.' files
|
98
|
+
# => ["test1", "test2", "some_directory_here"]
|
99
|
+
|
100
|
+
conn.items_in("directory_name")
|
101
|
+
# Traverses the provided directory returning an array of directories and files
|
102
|
+
# => ["test1", "test1/h1.rb", "test2", "test2/h2.txt"]
|
103
|
+
|
104
|
+
conn.print_directory_items("directory_name")
|
105
|
+
# a print out of contained directories/files one line at a time
|
106
|
+
# => test1.txt
|
107
|
+
# test2.png
|
108
|
+
# fun_directory_1
|
109
|
+
|
110
|
+
conn.glob("directory_name", "**/*.rb")
|
111
|
+
# Traverses the directory specified using the second argument/matcher
|
112
|
+
# So, you can get things like...
|
113
|
+
# => ["some_directory_here/hello_world.rb", "sftp_is_fun.rb"]
|
114
|
+
```
|
115
|
+
|
116
|
+
FileUtils
|
117
|
+
---------
|
118
|
+
|
119
|
+
FileUtilities are handy for doing some dirty work on the remote host.
|
120
|
+
|
121
|
+
So far, you can make/remove directories, remove/rename files
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
conn.mkdir!("new_directory_name_here")
|
125
|
+
```
|
126
|
+
|
127
|
+
Removing a directory is the same as above except you would swap mkdir! for rmdir!:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
conn.rmdir!("directory_name_to_remove")
|
131
|
+
```
|
132
|
+
|
133
|
+
Files can be removed and renamed off the remote host:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
conn.rm("file.txt")
|
137
|
+
|
138
|
+
conn.rename("old_file_name.txt", "new_file_name.txt")
|
139
|
+
# old_file_name.txt is now named new_file_name.txt on the remote host.
|
140
|
+
```
|
141
|
+
|
142
|
+
Hopefully, this is easy enough to work with and transfer files!!
|
143
|
+
|
144
|
+
Logging
|
145
|
+
-------
|
146
|
+
|
147
|
+
By default, logging is turned on and will use the Rails logger if within a Rails projects. If not logging will defer to STDOUT. Logging is prominent when downloading or uploading. To turn off logging, you can create an initializer and modify the configuration by:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
FunSftp.configure do |config|
|
151
|
+
config.log = false
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
You can also define your own logger if you'd like.
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
FunSftp.configure do |config|
|
159
|
+
config.logger = MyAwesomeLogger.new
|
160
|
+
end
|
161
|
+
```
|
162
|
+
|
163
|
+
Contribute
|
164
|
+
-------------------
|
165
|
+
|
166
|
+
1. Fork it
|
167
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
168
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
169
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
170
|
+
5. Create new Pull Request
|
171
|
+
|
172
|
+
License
|
173
|
+
-------
|
174
|
+
|
175
|
+
Copyright (c) 2013 George Diaz
|
176
|
+
|
177
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
178
|
+
|
179
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
180
|
+
|
181
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
182
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/fun_sftp.gemspec
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
module FunSftp
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
yield(configuration)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.logger
|
15
|
+
if loggable?
|
16
|
+
configuration and configuration.logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.loggable?
|
21
|
+
(configuration and !configuration.log) ? false : true
|
22
|
+
end
|
23
|
+
|
24
|
+
class Configuration
|
25
|
+
attr_accessor :log, :logger
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@log = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def log=(val)
|
32
|
+
if [true, false].include?(val)
|
33
|
+
@log = val
|
34
|
+
else
|
35
|
+
raise ArgumentError, "#{val} is not a correct value to set. Must be of either: [true, false]"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger
|
40
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FunSftp
|
2
|
+
class DownloadCallbacks
|
3
|
+
def on_open(downloader, file)
|
4
|
+
FunSftp.logger.info "starting download: #{file.remote} -> #{file.local} (#{file.size} bytes)"
|
5
|
+
end
|
6
|
+
|
7
|
+
def on_get(downloader, file, offset, data)
|
8
|
+
FunSftp.logger.info "writing #{data.length} bytes to #{file.local} starting at #{offset}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_close(downloader, file)
|
12
|
+
FunSftp.logger.info "finished with #{file.remote}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_mkdir(downloader, path)
|
16
|
+
FunSftp.logger.info "creating directory #{path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_finish(downloader)
|
20
|
+
FunSftp.logger.info "all done!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module FunSftp
|
2
|
+
class UploadCallbacks
|
3
|
+
def on_open(uploader, file)
|
4
|
+
FunSftp.logger.info "starting upload: #{file.local} -> #{file.remote} (#{file.size} bytes)"
|
5
|
+
end
|
6
|
+
|
7
|
+
def on_put(uploader, file, offset, data)
|
8
|
+
FunSftp.logger.info "writing #{data.length} bytes to #{file.remote} starting at #{offset}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_close(uploader, file)
|
12
|
+
FunSftp.logger.info "finished with #{file.remote}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def on_mkdir(uploader, path)
|
16
|
+
FunSftp.logger.info "creating directory #{path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_finish(uploader)
|
20
|
+
FunSftp.logger.info "all done!"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/fun_sftp/version.rb
CHANGED
data/lib/fun_sftp.rb
CHANGED
@@ -1,81 +1,146 @@
|
|
1
1
|
require 'fun_sftp/version'
|
2
|
+
require 'fun_sftp/configuration'
|
3
|
+
require 'fun_sftp/upload_callbacks'
|
4
|
+
require 'fun_sftp/download_callbacks'
|
2
5
|
|
3
|
-
#safe require
|
6
|
+
# safe require
|
7
|
+
# avoids any 'constant already init msg'
|
4
8
|
orig_verbose = $VERBOSE
|
5
9
|
$VERBOSE = nil
|
6
10
|
require 'net/sftp'
|
7
11
|
$VERBOSE = orig_verbose
|
8
12
|
|
13
|
+
# Reference: http://net-ssh.rubyforge.org/sftp/v2/api/
|
9
14
|
module FunSftp
|
10
|
-
|
11
15
|
class SFTPClient
|
12
|
-
attr_accessor :server, :user, :password, :client
|
16
|
+
attr_accessor :server, :user, :password, :client, :source
|
13
17
|
|
14
18
|
def initialize(server, user, password)
|
15
19
|
@server, @user, @password = server, user, password
|
20
|
+
@source = '.'
|
16
21
|
@client = setup_login
|
17
22
|
end
|
18
|
-
|
23
|
+
|
24
|
+
def source=(path)
|
25
|
+
@source = clean_path(path)
|
26
|
+
end
|
27
|
+
|
19
28
|
def setup_login
|
20
29
|
Net::SFTP.start(@server, @user, :password => @password)
|
21
30
|
end
|
22
|
-
|
31
|
+
|
23
32
|
def upload!(source, target) #send to remote
|
24
|
-
|
33
|
+
#target example: 'some_directory/some_name.txt'
|
34
|
+
opts = {:progress => UploadCallbacks.new, :recursive => true}
|
35
|
+
converted_target = join_to_pwd(target)
|
36
|
+
opts.delete(:progress) unless FunSftp.loggable?
|
37
|
+
opts.delete(:recursive) unless has_directory?(converted_target)
|
38
|
+
@client.upload!(source, converted_target, opts)
|
25
39
|
end
|
26
|
-
|
40
|
+
|
27
41
|
def download!(target, source) #fetch locally from remote
|
28
|
-
|
42
|
+
opts = {:progress => DownloadCallbacks.new, :recursive => true}
|
43
|
+
converted_target = join_to_pwd(target)
|
44
|
+
opts.delete(:progress) unless FunSftp.loggable?
|
45
|
+
opts.delete(:recursive) unless has_directory?(converted_target)
|
46
|
+
@client.download!(converted_target, source, opts)
|
29
47
|
end
|
30
|
-
|
48
|
+
|
31
49
|
def read(path) #read a file
|
32
|
-
file = @client.file.open(path)
|
50
|
+
file = @client.file.open(join_to_pwd(path))
|
33
51
|
while !file.eof?
|
34
52
|
puts file.gets
|
35
53
|
end
|
36
54
|
end
|
37
55
|
|
38
56
|
def glob(path, pattern) # ex: ('some_directory', '**/*.rb')
|
39
|
-
@client.dir.glob(path, pattern).collect(&:name)
|
57
|
+
@client.dir.glob(join_to_pwd(path), pattern).collect(&:name)
|
40
58
|
end
|
41
59
|
|
42
|
-
def entries(dir) #array of directory
|
43
|
-
@client.dir.entries(dir).collect(&:name)
|
60
|
+
def entries(dir, show_dot_files = false) #array of directory entries not caring for '.' files
|
61
|
+
entries_arr = @client.dir.entries(dir).collect(&:name)
|
62
|
+
entries_arr.reject!{|a| a.match(/^\..*$/)} unless show_dot_files
|
63
|
+
entries_arr
|
44
64
|
end
|
45
65
|
|
46
66
|
def has_directory?(dir) #returns true if directory exists
|
47
67
|
begin
|
48
68
|
true if entries(dir)
|
49
|
-
rescue
|
69
|
+
rescue Net::SFTP::StatusException => e
|
50
70
|
false
|
51
71
|
end
|
52
72
|
end
|
53
73
|
|
54
|
-
def print_directory_items(dir) #printout of directory items
|
55
|
-
@client.dir.foreach(dir) { |file|
|
74
|
+
def print_directory_items(dir) #printout of directory's items
|
75
|
+
@client.dir.foreach(join_to_pwd(dir)) { |file| puts "#{file.name}" }
|
56
76
|
end
|
57
77
|
|
58
78
|
def items_in(root_dir) #array of *all* directories & files inside provided root directory
|
59
79
|
glob(root_dir, '**/*').sort
|
60
80
|
end
|
61
|
-
|
62
|
-
|
81
|
+
|
82
|
+
#################################
|
83
|
+
# Some Handy File Util Methods #
|
84
|
+
#################################
|
85
|
+
|
63
86
|
def mkdir!(path) #make directory
|
64
|
-
@client.mkdir!
|
87
|
+
@client.mkdir!(join_to_pwd(path))
|
65
88
|
end
|
66
|
-
|
89
|
+
|
67
90
|
def rm(path) #remove a file
|
68
|
-
@client.remove!(path)
|
91
|
+
@client.remove!(join_to_pwd(path))
|
69
92
|
end
|
70
|
-
|
93
|
+
|
71
94
|
def rmdir!(path) #remove directory
|
72
|
-
@client.rmdir!(path)
|
95
|
+
@client.rmdir!(join_to_pwd(path))
|
73
96
|
end
|
74
|
-
|
97
|
+
|
75
98
|
def rename(name, new_name) #rename a file
|
76
|
-
|
99
|
+
previous, renamed = join_to_pwd(name), join_to_pwd(new_name)
|
100
|
+
@client.rename!(previous, renamed)
|
101
|
+
end
|
102
|
+
|
103
|
+
def ll
|
104
|
+
print_directory_items('.')
|
105
|
+
end
|
106
|
+
|
107
|
+
def chdir(path)
|
108
|
+
if path =~ /~/
|
109
|
+
new_path = clean_path(path)
|
110
|
+
change_directory_check(new_path, path)
|
111
|
+
else
|
112
|
+
change_directory_check(join_to_pwd(path), path)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def pwd
|
117
|
+
@source
|
118
|
+
end
|
119
|
+
|
120
|
+
def reset_path!
|
121
|
+
@source = '.'
|
122
|
+
"Path Reset and set to => #{@source}"
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def join_to_pwd(path)
|
128
|
+
File.join(@source, path)
|
129
|
+
end
|
130
|
+
|
131
|
+
def clean_path(path)
|
132
|
+
tilda_ith = path.rindex(/~/)
|
133
|
+
new_path = path[tilda_ith..-1].gsub(/~/, '.')
|
134
|
+
end
|
135
|
+
|
136
|
+
def change_directory_check(converted_path, entered_path)
|
137
|
+
if has_directory? converted_path
|
138
|
+
@source = converted_path
|
139
|
+
"Current Path changed to => #{@source}"
|
140
|
+
else
|
141
|
+
"Sorry Path => #{entered_path} not found"
|
142
|
+
end
|
77
143
|
end
|
78
|
-
##################################
|
79
144
|
|
80
145
|
end
|
81
146
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FunSftp
|
4
|
+
describe 'sftp client' do
|
5
|
+
|
6
|
+
let(:sftp_mock) {double('sftp')} #sftp_mock is the @client var
|
7
|
+
|
8
|
+
before do
|
9
|
+
Net::SFTP.stub(:start => sftp_mock)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'initialization' do
|
13
|
+
it 'should initialize with creds' do
|
14
|
+
expect(SFTPClient).to receive(:new).with('localhost', 'user1', 'pass')
|
15
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'file utilities' do
|
20
|
+
let(:file_1) {double("sftp_dir", :name => ".")}
|
21
|
+
let(:dir_1) {double("sftp_dir", :name => "import_docs")}
|
22
|
+
let(:dir_2) {double("sftp_dir", :name => "training_docs")}
|
23
|
+
|
24
|
+
it "should return entries without prepended '.' " do
|
25
|
+
sftp_mock.stub_chain(:dir, :entries).with(anything()).and_return([file_1, dir_1, dir_2])
|
26
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
27
|
+
expect(@sftp_cli.entries('Desktop')).to eq([dir_1.name, dir_2.name])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return with all files including '.' " do
|
31
|
+
sftp_mock.stub_chain(:dir, :entries).with(anything()).and_return([file_1, dir_1, dir_2])
|
32
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
33
|
+
expect(@sftp_cli.entries('Desktop', true)).to eq([file_1.name, dir_1.name, dir_2.name])
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should read both lines from test file' do
|
37
|
+
file = File.expand_path('../../support/test1.txt', __FILE__)
|
38
|
+
sftp_mock.stub_chain(:file, :open).with(anything()).and_return(File.open(file))
|
39
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
40
|
+
expect(@sftp_cli).to receive(:puts).twice
|
41
|
+
@sftp_cli.read(file)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return false for directory not found' do
|
45
|
+
sftp_response = Object.new
|
46
|
+
def sftp_response.code; code = 2 end
|
47
|
+
def sftp_response.message; message = 'no such file' end
|
48
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
49
|
+
@sftp_cli.stub(:entries).and_raise(Net::SFTP::StatusException.new(sftp_response))
|
50
|
+
expect(@sftp_cli.has_directory?('bogus_directory')).to eql(false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should change directory source path' do
|
54
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
55
|
+
@sftp_cli.stub(:has_directory?).with(anything()).and_return(true)
|
56
|
+
@sftp_cli.chdir('projects')
|
57
|
+
expect(@sftp_cli.source).to eql('./projects')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should sub tilda in path' do
|
61
|
+
@sftp_cli = SFTPClient.new('localhost', 'user1', 'pass')
|
62
|
+
@sftp_cli.stub(:has_directory?).with(anything()).and_return(true)
|
63
|
+
@sftp_cli.chdir('~/some_dir/working_dir')
|
64
|
+
expect(@sftp_cli.source).to eql('./some_dir/working_dir')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,101 +1,111 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_sftp
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 0.0.7
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- George Diaz
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: net-sftp
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
36
31
|
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
37
39
|
prerelease: false
|
38
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
47
54
|
type: :development
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Wrapper for Ruby's Net::SFTP library which makes SFTP easy! See Documentation
|
63
|
+
at https://github.com/georgediaz88/fun_sftp
|
64
|
+
email:
|
51
65
|
- georgediaz88@yahoo.com
|
52
66
|
executables: []
|
53
|
-
|
54
67
|
extensions: []
|
55
|
-
|
56
68
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
69
|
+
files:
|
59
70
|
- .gitignore
|
71
|
+
- .rspec
|
60
72
|
- Gemfile
|
61
|
-
- README.
|
73
|
+
- README.md
|
62
74
|
- Rakefile
|
63
75
|
- fun_sftp.gemspec
|
64
76
|
- lib/fun_sftp.rb
|
77
|
+
- lib/fun_sftp/configuration.rb
|
78
|
+
- lib/fun_sftp/download_callbacks.rb
|
79
|
+
- lib/fun_sftp/upload_callbacks.rb
|
65
80
|
- lib/fun_sftp/version.rb
|
66
|
-
|
81
|
+
- spec/fun_sftp/sftp_client_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
- spec/support/test1.txt
|
67
84
|
homepage: https://rubygems.org/gems/fun_sftp
|
68
85
|
licenses: []
|
69
|
-
|
70
86
|
post_install_message:
|
71
87
|
rdoc_options: []
|
72
|
-
|
73
|
-
require_paths:
|
88
|
+
require_paths:
|
74
89
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
91
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
81
|
-
|
82
|
-
- 0
|
83
|
-
version: "0"
|
84
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
97
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
version: "0"
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
93
102
|
requirements: []
|
94
|
-
|
95
103
|
rubyforge_project: fun_sftp
|
96
|
-
rubygems_version: 1.
|
104
|
+
rubygems_version: 1.8.25
|
97
105
|
signing_key:
|
98
106
|
specification_version: 3
|
99
107
|
summary: FunSFTP for secure file transfers
|
100
|
-
test_files:
|
101
|
-
|
108
|
+
test_files:
|
109
|
+
- spec/fun_sftp/sftp_client_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/support/test1.txt
|
data/README.rdoc
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
= FunSFTP (Version 0.0.7)
|
2
|
-
|
3
|
-
A Ruby Gem that provides a nice and easy to use wrapper for the Net::SFTP library.
|
4
|
-
|
5
|
-
Modeled from:
|
6
|
-
|
7
|
-
http://net-ssh.github.com/sftp/v2/api/index.html
|
8
|
-
|
9
|
-
|
10
|
-
== Install
|
11
|
-
|
12
|
-
Use Ruby versions >= 1.8.7
|
13
|
-
|
14
|
-
1) gem install fun_sftp
|
15
|
-
|
16
|
-
or in a Rails 3+ project:
|
17
|
-
|
18
|
-
2) gem 'fun_sftp'
|
19
|
-
|
20
|
-
and bundle away!
|
21
|
-
|
22
|
-
|
23
|
-
== Usage
|
24
|
-
|
25
|
-
Let's say you need to send a file to a remote host. Well, you can upload it to the remote host using these steps:
|
26
|
-
|
27
|
-
1) First setup the connection:
|
28
|
-
|
29
|
-
include FunSftp
|
30
|
-
conn = SFTPClient.new(server, username, password)
|
31
|
-
|
32
|
-
2) Now, you can upload your file:
|
33
|
-
|
34
|
-
conn.upload!("my_file_name.txt", "some_remote_directory/give_a_name.txt")
|
35
|
-
|
36
|
-
That's it! Check the remote host to see that your file posted.
|
37
|
-
|
38
|
-
You can also download a remote file to your local machine:
|
39
|
-
|
40
|
-
conn.download!("some_remote_directory/file_to_download_name.txt", "give_desired_local_name.txt")
|
41
|
-
|
42
|
-
Need to read a file on the remote host? Ah, it's no biggie...
|
43
|
-
|
44
|
-
conn.read("path/to/file_name.txt")
|
45
|
-
#=> Hello World!
|
46
|
-
|
47
|
-
When investigating items on the remote host, these commands can be handy:
|
48
|
-
|
49
|
-
1) conn.has_directory?("directory_name")
|
50
|
-
# returns true or false if the directory exists
|
51
|
-
|
52
|
-
2) conn.items_in("directory_name")
|
53
|
-
# returns an array of every directory and file within the provided directory
|
54
|
-
# => ["test1", "test1/h1.rb", "test2", "test2/h2.txt"]
|
55
|
-
|
56
|
-
3) conn.print_directory_items("directory_name")
|
57
|
-
# outputs directories one line at a time
|
58
|
-
# => test1
|
59
|
-
test2
|
60
|
-
some_directory_here
|
61
|
-
|
62
|
-
4) conn.entries("directory_name")
|
63
|
-
# outputs a nice array of entries in the specified directory
|
64
|
-
# => ["test1", "test2", "some_directory_here"]
|
65
|
-
|
66
|
-
5) conn.glob("directory_name", "**/*.rb")
|
67
|
-
# Traverses the directory specified using the second argument/matcher
|
68
|
-
# So, you can get things like...
|
69
|
-
# => ["some_directory_here/hello_world.rb", "sftp_is_fun.rb"]
|
70
|
-
|
71
|
-
== FileUtils
|
72
|
-
|
73
|
-
FileUtilities are handy for doing some dirty work on the remote host.
|
74
|
-
|
75
|
-
So far, you can make/remove directories, remove/rename files
|
76
|
-
|
77
|
-
1) conn.mkdir!("some_remote_directory/a_new_directory_name_here")
|
78
|
-
# makes a_new_directory_name_here under some_remote_directory if it exists
|
79
|
-
|
80
|
-
Removing a directory is the same as above except you would swap mkdir! for rmdir!:
|
81
|
-
|
82
|
-
2) conn.rmdir!("...")
|
83
|
-
|
84
|
-
Files can be removed and renamed off the remote host:
|
85
|
-
|
86
|
-
1) conn.rm("path/to/file.txt")
|
87
|
-
# would remove file.txt
|
88
|
-
|
89
|
-
2) conn.rename("old_file_name.txt", "new_file_name.txt")
|
90
|
-
# old_file_name.txt is now named new_file_name.txt on the remote host.
|
91
|
-
|
92
|
-
Hopefully, this is easy enough to work with and transfer files!!
|
93
|
-
Look for new helpful method calls in future releases.
|
94
|
-
|
95
|
-
== License
|
96
|
-
|
97
|
-
Copyright (c) 2012 George Diaz
|
98
|
-
|
99
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
100
|
-
a copy of this software and associated documentation files (the
|
101
|
-
"Software"), to deal in the Software without restriction, including
|
102
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
103
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
104
|
-
permit persons to whom the Software is furnished to do so, subject to
|
105
|
-
the following conditions:
|
106
|
-
|
107
|
-
The above copyright notice and this permission notice shall be
|
108
|
-
included in all copies or substantial portions of the Software.
|
109
|
-
|
110
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
111
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
112
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
113
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
114
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
115
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
116
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|