carrierwave-ftp 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72042eaccd1416fe327ba26b7210442e5247ed24
4
- data.tar.gz: fbaec8655d9b81609faac3724d857e2a06c81d45
3
+ metadata.gz: df0afee16e1ea7ec251387b0d40e51b34125f393
4
+ data.tar.gz: 60e317278e41bce9435f0ae5a2f91b34ce354575
5
5
  SHA512:
6
- metadata.gz: f69cc5ac46c1064368b7b808f4c450f0050dfaaab5714e0cb2cba3664e6fed5866f4df72fb98305247db521bd4286b6f35c172212806bff257358c871f41b440
7
- data.tar.gz: fbd2cf91d00c678d834b8d9db8522a457cf7df68d65113a42003079962c717d6bb9c63ef2983a00edf175697550135368a54a46d05a7579ea7fc8255e3d795df
6
+ metadata.gz: 1b8ba3eb90cf8cace416957dfa485cd14c0b62bd3c8e1946df51d68b39d8d60fd43ffb69323eb4ecc3a68843603626b3733a8e66dac2fd7767ff632a236bf0e2
7
+ data.tar.gz: c966647c7f64e7d23f61cb911b0617bfaedef048c62178ff4aa807ef5148cc31918bdbd1f4a12479eaf9ce4277fea00adb8af47f33da44d8f7e2525a0afe6bec
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.4
2
+
3
+ RUN mkdir -p /gem
4
+ WORKDIR /gem
5
+
6
+ ADD . ./
7
+
8
+ RUN gem install bundler && bundle install --jobs 20 --retry 5
data/README.md CHANGED
@@ -35,6 +35,7 @@ CarrierWave.configure do |config|
35
35
  config.ftp_folder = "/public_html/uploads"
36
36
  config.ftp_url = "http://example.com/uploads"
37
37
  config.ftp_passive = false # false by default
38
+ config.ftp_tls = false # false by default
38
39
  end
39
40
  ```
40
41
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency "carrierwave", [">= 0.6.2"]
24
24
  s.add_dependency "net-sftp", ["~> 2.1.2"]
25
+ s.add_dependency "double-bag-ftps", ["0.1.3"]
25
26
  s.add_development_dependency "rspec", ["~> 2.14"]
26
27
  s.add_development_dependency "rake", ["~> 10.3"]
27
28
  end
@@ -0,0 +1,11 @@
1
+ version: '3'
2
+
3
+ services:
4
+ gem:
5
+ build: .
6
+ volumes:
7
+ - .:/gem
8
+ - bundler:/usr/local/bundle
9
+
10
+ volumes:
11
+ bundler:
@@ -1,5 +1,6 @@
1
1
  require 'carrierwave'
2
2
  require 'carrierwave/storage/ftp/ex_ftp'
3
+ require 'carrierwave/storage/ftp/ex_ftptls'
3
4
 
4
5
  module CarrierWave
5
6
  module Storage
@@ -26,6 +27,9 @@ module CarrierWave
26
27
  ftp.mkdir_p(::File.dirname "#{@uploader.ftp_folder}/#{path}")
27
28
  ftp.chdir(::File.dirname "#{@uploader.ftp_folder}/#{path}")
28
29
  ftp.put(file.path, filename)
30
+ if @uploader.ftp_chmod
31
+ ftp.sendcmd("SITE CHMOD #{@uploader.permissions.to_s(8)} #{@uploader.ftp_folder}/#{path}")
32
+ end
29
33
  end
30
34
  end
31
35
 
@@ -91,7 +95,12 @@ module CarrierWave
91
95
  private
92
96
 
93
97
  def connection
94
- ftp = ExFTP.new
98
+ if @uploader.ftp_tls
99
+ ftp = ExFTPTLS.new
100
+ ftp.ssl_context = DoubleBagFTPS.create_ssl_context(:verify_mode => OpenSSL::SSL::VERIFY_NONE)
101
+ else
102
+ ftp = ExFTP.new
103
+ end
95
104
  ftp.connect(@uploader.ftp_host, @uploader.ftp_port)
96
105
 
97
106
  begin
@@ -118,6 +127,8 @@ class CarrierWave::Uploader::Base
118
127
  add_config :ftp_folder
119
128
  add_config :ftp_url
120
129
  add_config :ftp_passive
130
+ add_config :ftp_tls
131
+ add_config :ftp_chmod
121
132
 
122
133
  configure do |config|
123
134
  config.storage_engines[:ftp] = "CarrierWave::Storage::FTP"
@@ -128,5 +139,7 @@ class CarrierWave::Uploader::Base
128
139
  config.ftp_folder = "/"
129
140
  config.ftp_url = "http://localhost"
130
141
  config.ftp_passive = false
142
+ config.ftp_tls = false
143
+ config.ftp_chmod = true
131
144
  end
132
145
  end
@@ -1,2 +1,2 @@
1
1
  require 'carrierwave/storage/ftp'
2
- require 'carrierwave/storage/sftp'
2
+ require 'carrierwave/storage/sftp'
@@ -0,0 +1,25 @@
1
+ require 'double_bag_ftps'
2
+
3
+ class ExFTPTLS < DoubleBagFTPS
4
+ def mkdir_p(dir)
5
+ parts = dir.split("/")
6
+ if parts.first == "~"
7
+ growing_path = ""
8
+ else
9
+ growing_path = "/"
10
+ end
11
+ for part in parts
12
+ next if part == ""
13
+ if growing_path == ""
14
+ growing_path = part
15
+ else
16
+ growing_path = File.join(growing_path, part)
17
+ end
18
+ begin
19
+ mkdir(growing_path)
20
+ chdir(growing_path)
21
+ rescue Net::FTPPermError, Net::FTPTempError => e
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,7 +1,7 @@
1
1
  module Carrierwave
2
2
  module Storage
3
3
  class FTP
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  describe CarrierWave::Storage::FTP do
9
9
  before do
10
- CarrierWave.configure do |config|
10
+ FtpUploader.configure do |config|
11
11
  config.reset_config
12
12
  config.ftp_host = 'ftp.testcarrierwave.dev'
13
13
  config.ftp_user = 'test_user'
@@ -15,6 +15,7 @@ describe CarrierWave::Storage::FTP do
15
15
  config.ftp_folder = '~/public_html'
16
16
  config.ftp_url = 'http://testcarrierwave.dev'
17
17
  config.ftp_passive = true
18
+ config.ftp_chmod = true
18
19
  end
19
20
 
20
21
  @file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
@@ -38,10 +39,39 @@ describe CarrierWave::Storage::FTP do
38
39
  ftp.should_receive(:mkdir_p).with('~/public_html/uploads')
39
40
  ftp.should_receive(:chdir).with('~/public_html/uploads')
40
41
  ftp.should_receive(:put).with(@file.path, 'test.jpg')
42
+ ftp.should_receive(:sendcmd).with("SITE CHMOD 644 ~/public_html/uploads/test.jpg")
41
43
  ftp.should_receive(:quit)
42
44
  @stored = @storage.store!(@file)
43
45
  end
44
46
 
47
+ describe 'when CHMOD is disabled' do
48
+ before do
49
+ FtpUploader.configure do |config|
50
+ config.ftp_chmod = false
51
+ end
52
+ end
53
+
54
+ it "opens/closes an ftp connection to the given host" do
55
+ ftp = double(:ftp_connection)
56
+ ftp_params = [
57
+ 'ftp.testcarrierwave.dev',
58
+ 'test_user',
59
+ 'test_passwd',
60
+ 21
61
+ ]
62
+
63
+ Net::FTP.should_receive(:new).and_return(ftp)
64
+ ftp.should_receive(:connect).with('ftp.testcarrierwave.dev', 21)
65
+ ftp.should_receive(:login).with('test_user', 'test_passwd')
66
+ ftp.should_receive(:passive=).with(true)
67
+ ftp.should_receive(:mkdir_p).with('~/public_html/uploads')
68
+ ftp.should_receive(:chdir).with('~/public_html/uploads')
69
+ ftp.should_receive(:put).with(@file.path, 'test.jpg')
70
+ ftp.should_receive(:quit)
71
+ @stored = @storage.store!(@file)
72
+ end
73
+ end
74
+
45
75
  describe 'after upload' do
46
76
  before do
47
77
  ftp = double(:ftp_connection)
@@ -52,6 +82,7 @@ describe CarrierWave::Storage::FTP do
52
82
  ftp.stub(:mkdir_p)
53
83
  ftp.stub(:chdir)
54
84
  ftp.stub(:put)
85
+ ftp.stub(:sendcmd)
55
86
  ftp.stub(:quit)
56
87
  @stored = @storage.store!(@file)
57
88
  end
@@ -75,6 +106,7 @@ describe CarrierWave::Storage::FTP do
75
106
  @ftp.stub(:mkdir_p)
76
107
  @ftp.stub(:chdir)
77
108
  @ftp.stub(:put)
109
+ @ftp.stub(:sendcmd)
78
110
  @ftp.stub(:quit)
79
111
  @stored = @storage.store!(@file)
80
112
  end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'carrierwave/storage/ftp'
3
+
4
+ class FtpTlsUploader < CarrierWave::Uploader::Base
5
+ storage :ftp
6
+ end
7
+
8
+ describe CarrierWave::Storage::FTP do
9
+ before do
10
+ FtpTlsUploader.configure do |config|
11
+ config.reset_config
12
+ config.ftp_host = 'ftp.testcarrierwave.dev'
13
+ config.ftp_user = 'test_user'
14
+ config.ftp_passwd = 'test_passwd'
15
+ config.ftp_folder = '~/public_html'
16
+ config.ftp_url = 'http://testcarrierwave.dev'
17
+ config.ftp_passive = true
18
+ config.ftp_tls = true
19
+ config.ftp_chmod = true
20
+ end
21
+
22
+ @file = CarrierWave::SanitizedFile.new(file_path('test.jpg'))
23
+ FtpTlsUploader.stub(:store_path).and_return('uploads/test.jpg')
24
+ @storage = CarrierWave::Storage::FTP.new(FtpTlsUploader)
25
+ end
26
+
27
+ it "opens/closes a secure ftp connection to the given host" do
28
+ ftp = double(:ftp_connection)
29
+ Net::FTP.should_receive(:new).and_return(ftp)
30
+ ftp.should_receive(:sendcmd)
31
+ ftp.should_receive(:ssl_context=)
32
+ ftp.should_receive(:connect).with('ftp.testcarrierwave.dev', 21)
33
+ ftp.should_receive(:login).with('test_user', 'test_passwd')
34
+ ftp.should_receive(:passive=).with(true)
35
+ ftp.should_receive(:mkdir_p).with('~/public_html/uploads')
36
+ ftp.should_receive(:chdir).with('~/public_html/uploads')
37
+ ftp.should_receive(:put).with(@file.path, 'test.jpg')
38
+ ftp.should_receive(:quit)
39
+ @stored = @storage.store!(@file)
40
+ end
41
+
42
+ describe 'when CHMOD is disabled' do
43
+ before do
44
+ FtpTlsUploader.configure do |config|
45
+ config.ftp_chmod = false
46
+ end
47
+ end
48
+
49
+ it "opens/closes a secure ftp connection to the given host" do
50
+ ftp = double(:ftp_connection)
51
+ Net::FTP.should_receive(:new).and_return(ftp)
52
+ ftp.should_receive(:ssl_context=)
53
+ ftp.should_receive(:connect).with('ftp.testcarrierwave.dev', 21)
54
+ ftp.should_receive(:login).with('test_user', 'test_passwd')
55
+ ftp.should_receive(:passive=).with(true)
56
+ ftp.should_receive(:mkdir_p).with('~/public_html/uploads')
57
+ ftp.should_receive(:chdir).with('~/public_html/uploads')
58
+ ftp.should_receive(:put).with(@file.path, 'test.jpg')
59
+ ftp.should_receive(:quit)
60
+ @stored = @storage.store!(@file)
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luan Santos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: double-bag-ftps
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.3
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -76,18 +90,22 @@ files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
78
92
  - ".travis.yml"
93
+ - Dockerfile
79
94
  - Gemfile
80
95
  - LICENSE
81
96
  - README.md
82
97
  - Rakefile
83
- - carrerwave-ftp.gemspec
98
+ - carrierwave-ftp.gemspec
99
+ - docker-compose.yml
84
100
  - lib/carrierwave/storage/ftp.rb
85
101
  - lib/carrierwave/storage/ftp/all.rb
86
102
  - lib/carrierwave/storage/ftp/ex_ftp.rb
103
+ - lib/carrierwave/storage/ftp/ex_ftptls.rb
87
104
  - lib/carrierwave/storage/ftp/ex_sftp.rb
88
105
  - lib/carrierwave/storage/ftp/version.rb
89
106
  - lib/carrierwave/storage/sftp.rb
90
107
  - spec/ftp_spec.rb
108
+ - spec/ftp_tls_spec.rb
91
109
  - spec/sftp_spec.rb
92
110
  - spec/spec_helper.rb
93
111
  homepage: https://github.com/luan/carrierwave-ftp
@@ -110,11 +128,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
128
  version: '0'
111
129
  requirements: []
112
130
  rubyforge_project: carrierwave-ftp
113
- rubygems_version: 2.5.1
131
+ rubygems_version: 2.6.13
114
132
  signing_key:
115
133
  specification_version: 4
116
134
  summary: FTP support for CarrierWave
117
135
  test_files:
118
136
  - spec/ftp_spec.rb
137
+ - spec/ftp_tls_spec.rb
119
138
  - spec/sftp_spec.rb
120
139
  - spec/spec_helper.rb