fun_sftp 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
- = FunSFTP (Version 0.0.5)
1
+ = FunSFTP (Version 0.0.6)
2
2
 
3
- Ruby Gem that provides a nice and easy to work with wrapper for the Net::SFTP library.
3
+ A Ruby Gem that provides a nice and easy to use wrapper for the Net::SFTP library.
4
4
 
5
5
  Modeled from:
6
6
 
@@ -9,52 +9,64 @@ http://net-ssh.github.com/sftp/v2/api/index.html
9
9
 
10
10
  == Install
11
11
 
12
- gem install fun_sftp
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'
13
19
 
14
- In Rails: gem 'fun_sftp'
20
+ and bundle away!
15
21
 
16
22
 
17
23
  == Usage
18
24
 
19
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:
20
26
 
21
- #First setup the connection:
22
- include FunSftp
27
+ 1) First setup the connection:
23
28
 
24
- conn = SFTPClient.new(server, username, password)
29
+ include FunSftp
30
+ conn = SFTPClient.new(server, username, password)
25
31
 
26
- #Now, you can upload your file:
32
+ 2) Now, you can upload your file:
27
33
 
28
- conn.upload!("my_file_name.txt", "some_directory/give_a_name.txt")
34
+ conn.upload!("my_file_name.txt", "some_remote_directory/give_a_name.txt")
29
35
 
30
- That's it! Check the remote host and see that your file posted.
36
+ That's it! Check the remote host to see that your file posted.
31
37
 
32
- You can also download a file locally by:
38
+ You can also download a remote file to your local machine:
33
39
 
34
- conn.download!("some_directory/file_to_download_name.txt", "give_the_local_name.txt")
40
+ conn.download!("some_remote_directory/file_to_download_name.txt", "give_desired_local_name.txt")
35
41
 
36
- Need to read a file on the remote host? No biggie...
42
+ Need to read a file on the remote host? Ah, it's no biggie...
37
43
 
38
- conn.read("path/to/file")
39
- # => Here is content in your requested file.
44
+ conn.read("path/to/file_name.txt")
45
+ #=> Hello World!
40
46
 
41
- When investigating items in the remote host, these can be handy:
47
+ When investigating items on the remote host, these commands can be handy:
42
48
 
43
- Command: conn.print_directory_items("directory_name")
44
- #=> outputs directories
45
- test1
46
- test2
47
- some_directory_here
48
-
49
- Command: conn.entries("directory_name")
50
- #=> outputs a nice array of entries in the specified directory
51
- ["test1", "test2", "some_directory_here"]
52
-
53
- Command: conn.glob("directory_name", "**/*.rb")
54
- #=> Pattern matches the second argument in the directory_name given
55
- #=> So, you can get things like...
56
- some_directory_here/hello_world.rb
57
- some_directory_here/sftp_is_fun.rb
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"]
58
70
 
59
71
  == FileUtils
60
72
 
@@ -62,22 +74,23 @@ FileUtilities are handy for doing some dirty work on the remote host.
62
74
 
63
75
  So far, you can make/remove directories, remove/rename files
64
76
 
65
- Command: conn.mkdir!("some_directory/a_new_directory_name_here")
66
- #=> makes a_new_directory_name_here under some_directory which exists
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
67
79
 
68
- Removing a directory is the same as above except you would now specify:
80
+ Removing a directory is the same as above except you would swap mkdir! for rmdir!:
69
81
 
70
- conn.rmdir!
82
+ 2) conn.rmdir!("...")
71
83
 
72
- Files can be renamed and removed off the remote:
84
+ Files can be removed and renamed off the remote host:
73
85
 
74
- Command: conn.rm("path/to/file.txt")
75
- #=> would remove file.txt
86
+ 1) conn.rm("path/to/file.txt")
87
+ # would remove file.txt
76
88
 
77
- Command: conn.rename("old_file_name.txt", "new_file_name.txt")
78
- #=> old_file_name.txt is now named new_file_name.txt on remote host.
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.
79
91
 
80
- Hopefully, this is basic enough to work with and transfer files!!
92
+ Hopefully, this is easy enough to work with and transfer files!!
93
+ Look for new helpful method calls in future releases.
81
94
 
82
95
  == License
83
96
 
@@ -1,3 +1,3 @@
1
1
  module FunSftp
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/fun_sftp.rb CHANGED
@@ -38,14 +38,26 @@ module FunSftp
38
38
  def glob(path, pattern) # ex: ('some_directory', '**/*.rb')
39
39
  @client.dir.glob(path, pattern).collect(&:name)
40
40
  end
41
-
41
+
42
42
  def entries(dir) #array of directory items
43
- @client.dir.entries(dir).collect(&:name)
43
+ @client.dir.entries(dir).collect(&:name).reject!{|a| a.match(/^\.+$/)}
44
+ end
45
+
46
+ def has_directory?(dir) #returns true if directory exists
47
+ begin
48
+ true if entries(dir)
49
+ rescue Exception => e
50
+ false
51
+ end
44
52
  end
45
53
 
46
54
  def print_directory_items(dir) #printout of directory items
47
55
  @client.dir.foreach(dir) { |file| print "#{file.name}\n" }
48
56
  end
57
+
58
+ def items_in(root_dir) #array of *all* directories & files inside provided root directory
59
+ glob(root_dir, '**/*').sort
60
+ end
49
61
 
50
62
  #### Some Handy File Util Methods
51
63
  def mkdir!(path) #make directory
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fun_sftp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - George Diaz