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 +54 -41
- data/lib/fun_sftp/version.rb +1 -1
- data/lib/fun_sftp.rb +14 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
= FunSFTP (Version 0.0.
|
1
|
+
= FunSFTP (Version 0.0.6)
|
2
2
|
|
3
|
-
Ruby Gem that provides a nice and easy to
|
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
|
-
|
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
|
-
|
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
|
-
|
22
|
-
include FunSftp
|
27
|
+
1) First setup the connection:
|
23
28
|
|
24
|
-
|
29
|
+
include FunSftp
|
30
|
+
conn = SFTPClient.new(server, username, password)
|
25
31
|
|
26
|
-
|
32
|
+
2) Now, you can upload your file:
|
27
33
|
|
28
|
-
|
34
|
+
conn.upload!("my_file_name.txt", "some_remote_directory/give_a_name.txt")
|
29
35
|
|
30
|
-
That's it! Check the remote host
|
36
|
+
That's it! Check the remote host to see that your file posted.
|
31
37
|
|
32
|
-
You can also download a file
|
38
|
+
You can also download a remote file to your local machine:
|
33
39
|
|
34
|
-
conn.download!("
|
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?
|
42
|
+
Need to read a file on the remote host? Ah, it's no biggie...
|
37
43
|
|
38
|
-
conn.read("path/to/
|
39
|
-
|
44
|
+
conn.read("path/to/file_name.txt")
|
45
|
+
#=> Hello World!
|
40
46
|
|
41
|
-
When investigating items
|
47
|
+
When investigating items on the remote host, these commands can be handy:
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
66
|
-
|
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
|
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
|
84
|
+
Files can be removed and renamed off the remote host:
|
73
85
|
|
74
|
-
|
75
|
-
|
86
|
+
1) conn.rm("path/to/file.txt")
|
87
|
+
# would remove file.txt
|
76
88
|
|
77
|
-
|
78
|
-
|
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
|
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
|
|
data/lib/fun_sftp/version.rb
CHANGED
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