ftputils 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/lib/ftputils/ftpfile.rb +8 -3
- data/lib/ftputils.rb +7 -1
- data/spec/ftpfile_spec.rb +11 -0
- data/spec/ftputils_spec.rb +19 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
=
|
1
|
+
= FTPUtils
|
2
2
|
|
3
|
-
|
3
|
+
FTPUtils attempts to reproduce a subset of the methods provided by FileUtils and File for FTP URIs, using Net::FTP. While it has decent coverage by Rspec specs, it has only been tested under conditions specific to what it was developed for and will very likely need more work to be generally useful.
|
4
4
|
|
5
5
|
== Note on Patches/Pull Requests
|
6
6
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/ftputils/ftpfile.rb
CHANGED
@@ -44,9 +44,14 @@ class FTPUtils
|
|
44
44
|
if ftp_uri = FTPUtils::FTPURI.parse(path)
|
45
45
|
connection = FTPUtils::FTPConnection.connect(path)
|
46
46
|
connection.chdir ftp_uri.dirname
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
|
48
|
+
begin
|
49
|
+
if connection.size(ftp_uri.filename) > 0
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
rescue
|
50
55
|
return false
|
51
56
|
end
|
52
57
|
else
|
data/lib/ftputils.rb
CHANGED
@@ -9,6 +9,7 @@ require 'fileutils'
|
|
9
9
|
require 'open-uri'
|
10
10
|
|
11
11
|
class FTPUtils
|
12
|
+
|
12
13
|
def self.cp(src, dest, options = {})
|
13
14
|
# handle all combinations of copying to/from FTP and local files
|
14
15
|
case [ftp_url?(src), ftp_url?(dest)]
|
@@ -40,7 +41,12 @@ class FTPUtils
|
|
40
41
|
|
41
42
|
connection = FTPConnection.connect(dest)
|
42
43
|
connection.chdir FTPFile.dirname(dest)
|
43
|
-
|
44
|
+
|
45
|
+
begin
|
46
|
+
connection.putbinaryfile src, dest_path, 1024
|
47
|
+
rescue Net::FTPPermError
|
48
|
+
raise "Unable to copy #{src} to #{dest_path}, possibly due to FTP server permissions"
|
49
|
+
end
|
44
50
|
when [false, false]
|
45
51
|
FileUtils.cp src, dest, options
|
46
52
|
end
|
data/spec/ftpfile_spec.rb
CHANGED
@@ -69,6 +69,17 @@ describe FTPUtils::FTPURI do
|
|
69
69
|
FTPUtils::FTPFile.exists?("ftp://admin:test@myhost/path/to/file.txt").should be_false
|
70
70
|
end
|
71
71
|
|
72
|
+
it "should be false when Net::FTPPermError is raised" do
|
73
|
+
mock_uri = mock(FTPUtils::FTPURI, :path => "/path/to/file.txt", :dirname => "/path/to", :filename => "file.txt")
|
74
|
+
FTPUtils::FTPURI.should_receive(:parse).with("ftp://admin:test@myhost/path/to/file.txt").and_return(mock_uri)
|
75
|
+
mock_connection = mock(FTPUtils::FTPConnection)
|
76
|
+
FTPUtils::FTPConnection.should_receive(:connect).with("ftp://admin:test@myhost/path/to/file.txt").and_return(mock_connection)
|
77
|
+
mock_connection.should_receive(:chdir).with("/path/to")
|
78
|
+
mock_connection.should_receive(:size).with("file.txt").and_raise(Net::FTPPermError)
|
79
|
+
|
80
|
+
FTPUtils::FTPFile.exists?("ftp://admin:test@myhost/path/to/file.txt").should be_false
|
81
|
+
end
|
82
|
+
|
72
83
|
it "should pass the path to File.exists? if it's not an FTP URI" do
|
73
84
|
FTPUtils::FTPURI.should_receive(:parse).with("/path/to/file.txt").and_return(nil)
|
74
85
|
File.should_receive(:exists?)
|
data/spec/ftputils_spec.rb
CHANGED
@@ -163,6 +163,25 @@ describe "FTPUtils" do
|
|
163
163
|
FTPUtils.cp "/home/me/file1.txt", "ftp://admin:test@host2"
|
164
164
|
end
|
165
165
|
|
166
|
+
it "should provide an informative error message if the file can't be uploaded" do
|
167
|
+
File.should_receive(:directory?).with("/home/me/file1.txt").and_return(false)
|
168
|
+
FTPUtils::FTPFile.should_receive(:relative_path).with("ftp://admin:test@host2/file2.txt").
|
169
|
+
and_return("/file2.txt")
|
170
|
+
FTPUtils::FTPFile.should_receive(:directory?).with("ftp://admin:test@host2/file2.txt").
|
171
|
+
and_return(false)
|
172
|
+
mock_dest_connection = mock(FTPUtils::FTPConnection)
|
173
|
+
FTPUtils::FTPConnection.should_receive(:connect).with("ftp://admin:test@host2/file2.txt").
|
174
|
+
and_return(mock_dest_connection)
|
175
|
+
FTPUtils::FTPFile.should_receive(:dirname).with("ftp://admin:test@host2/file2.txt").and_return("/")
|
176
|
+
mock_dest_connection.should_receive(:chdir).with("/")
|
177
|
+
mock_dest_connection.should_receive(:putbinaryfile).with("/home/me/file1.txt", "/file2.txt", 1024).
|
178
|
+
and_raise(Net::FTPPermError)
|
179
|
+
|
180
|
+
lambda do
|
181
|
+
FTPUtils.cp "/home/me/file1.txt", "ftp://admin:test@host2/file2.txt"
|
182
|
+
end.should raise_error("Unable to copy /home/me/file1.txt to /file2.txt, possibly due to FTP server permissions")
|
183
|
+
end
|
184
|
+
|
166
185
|
it "should raise an error if the source file is a directory" do
|
167
186
|
File.should_receive(:directory?).with("/home/me").and_return(true)
|
168
187
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bruz Marzolf
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-04 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|