autosftp 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/README.md +41 -0
- data/lib/autosftp/cli.rb +11 -1
- data/lib/autosftp/connection.rb +11 -25
- data/lib/autosftp/monitor.rb +3 -3
- data/lib/autosftp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 732e795b1614d34bb2f383007819c836d291038b
|
4
|
+
data.tar.gz: 2a8844beba485d36aafebf4445d7106539433bb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5566552f82b876ab954d038d07a2d6f478d40bf173600a0b145cde7ed384c9da3ecdaa507273dc05bd897cde9bd39ac666d61f7707a786443ef7a8d9b385521a
|
7
|
+
data.tar.gz: e891ddd5f542945dec0df654679140f54e58baa0d5358ad0f91d9a9ff9a700fa64cbd560cc781328588beb2e8ae946be25dee14ed60991ead2624ead095e06ed
|
data/README.md
CHANGED
@@ -34,6 +34,13 @@ yaml形式で.autosftpというファイルが作成されます。
|
|
34
34
|
|
35
35
|
$ autosftp start [remote name]
|
36
36
|
|
37
|
+
後ろにディレクトリを渡すことで、監視するディレクトリ先を選択することが出来ます。
|
38
|
+
setしたローカルディレクトリ移行のパスを指定して下さい。
|
39
|
+
|
40
|
+
$ autosftp start [remote name] /app/
|
41
|
+
# いくつでも渡すことが出来ます。
|
42
|
+
$ autosftp start [remote name] /app/ /vender/
|
43
|
+
|
37
44
|
設定したsftpの情報を確認します。
|
38
45
|
|
39
46
|
$ autosftp list
|
@@ -42,6 +49,40 @@ yaml形式で.autosftpというファイルが作成されます。
|
|
42
49
|
|
43
50
|
$ autosftp delete [remote name]
|
44
51
|
|
52
|
+
## 設定のサンプル
|
53
|
+
|
54
|
+
プロジェクトのディレクトリに移動します。
|
55
|
+
(プロジェクトが/User/username/projectと仮定する。)
|
56
|
+
|
57
|
+
$ cd /User/username/project
|
58
|
+
|
59
|
+
autosftpの設定ファイルを作成します。
|
60
|
+
|
61
|
+
$ autosftp init
|
62
|
+
|
63
|
+
SFTPの設定を行います。
|
64
|
+
ここで重要なのが、ローカルのパスとリモートのパスを合わせる必要があります。
|
65
|
+
[remote name]は自由な名称をつけて下さい。
|
66
|
+
|
67
|
+
$ autosftp set [remote name]
|
68
|
+
|
69
|
+
一度設定ファイル(.autosftp)を確認したほうが良いです。
|
70
|
+
中身が以下のようになっていたら設定完了です。
|
71
|
+
`remote_path` と `local_path` のパスは合わせて下さい。
|
72
|
+
|
73
|
+
---
|
74
|
+
: [remote name]
|
75
|
+
:user: username
|
76
|
+
:host: test.com
|
77
|
+
:port: 22
|
78
|
+
:password: password
|
79
|
+
:remote_path: /var/www/html/
|
80
|
+
:local_path: /User/username/project/
|
81
|
+
|
82
|
+
監視をスタートします。
|
83
|
+
|
84
|
+
$ autosftp start [remote name]
|
85
|
+
|
45
86
|
## これからの予定
|
46
87
|
|
47
88
|
- 鍵認証出来るようにする。
|
data/lib/autosftp/cli.rb
CHANGED
@@ -8,6 +8,7 @@ module Autosftp
|
|
8
8
|
class CLI < Thor
|
9
9
|
|
10
10
|
desc "start [remote name]", "Automatic monitoring start"
|
11
|
+
option :chmod
|
11
12
|
def start(*word)
|
12
13
|
if false == Autosftp::FileAccess.exist?
|
13
14
|
puts "is not .autosftp \n $ autosftp init"
|
@@ -29,7 +30,16 @@ module Autosftp
|
|
29
30
|
dir = '**/*'
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
+
permission = {}
|
34
|
+
if options[:chmod]
|
35
|
+
permission[:dir] = options[:chmod]
|
36
|
+
permission[:file] = options[:chmod]
|
37
|
+
else
|
38
|
+
permission[:dir] = 755
|
39
|
+
permission[:file] = 644
|
40
|
+
end
|
41
|
+
|
42
|
+
Autosftp::Monitor.start setting, dir, permission
|
33
43
|
end
|
34
44
|
|
35
45
|
desc "set [remote name]", "add information to the '.autosftp'. Please put the name of any [remote name]"
|
data/lib/autosftp/connection.rb
CHANGED
@@ -33,23 +33,12 @@ module Autosftp
|
|
33
33
|
end
|
34
34
|
|
35
35
|
# ファイルの新規作成+更新
|
36
|
-
def self.create ssh_hash, local_file, remote_file
|
36
|
+
def self.create ssh_hash, local_file, remote_file, permission
|
37
37
|
Net::SSH.start(ssh_hash[:host], ssh_hash[:user], {:password => ssh_hash[:password], :port => ssh_hash[:port]}) do |ssh|
|
38
|
-
ssh.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if File.exist? local_file
|
43
|
-
sftp.upload!(local_file, remote_file)
|
44
|
-
end
|
45
|
-
rescue Net::SFTP::StatusException => e
|
46
|
-
raise unless e.code == 2
|
47
|
-
if File.exist? local_file
|
48
|
-
sftp.upload!(local_file, remote_file)
|
49
|
-
sftp.setstat(remote_file, :permissions => 0644)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
38
|
+
ssh_dir(ssh, File.dirname(remote_file), permission)
|
39
|
+
if File.exist? local_file
|
40
|
+
ssh.sftp.upload!(local_file, remote_file)
|
41
|
+
ssh.exec! "chmod #{permission[:file]} #{remote_file}"
|
53
42
|
end
|
54
43
|
end
|
55
44
|
end
|
@@ -57,20 +46,17 @@ module Autosftp
|
|
57
46
|
# ファイルの削除
|
58
47
|
def self.delete ssh_hash, remote_file
|
59
48
|
Net::SSH.start(ssh_hash[:host], ssh_hash[:user], {:password => ssh_hash[:password], :port => ssh_hash[:port]}) do |ssh|
|
60
|
-
ssh.sftp.
|
61
|
-
sftp.remove!(remote_file)
|
62
|
-
end
|
49
|
+
ssh.sftp.remove!(remote_file)
|
63
50
|
end
|
64
|
-
rescue
|
65
51
|
end
|
66
52
|
|
67
53
|
# ディレクトリの作成
|
68
|
-
def self.ssh_dir
|
69
|
-
sftp.stat!(path)
|
70
|
-
rescue
|
54
|
+
def self.ssh_dir ssh, path, permission
|
55
|
+
ssh.sftp.stat!(path)
|
56
|
+
rescue
|
71
57
|
parent = File::dirname(path);
|
72
|
-
ssh_dir(
|
73
|
-
sftp.mkdir!(path, :permissions =>
|
58
|
+
ssh_dir(ssh, parent)
|
59
|
+
ssh.sftp.mkdir!(path, :permissions => permission[:dir])
|
74
60
|
end
|
75
61
|
|
76
62
|
end
|
data/lib/autosftp/monitor.rb
CHANGED
@@ -4,7 +4,7 @@ require 'autosftp/connection'
|
|
4
4
|
|
5
5
|
module Autosftp
|
6
6
|
class Monitor
|
7
|
-
def self.start setting, dir
|
7
|
+
def self.start setting, dir, permission
|
8
8
|
FSSM.monitor(setting[:local_path], dir) do
|
9
9
|
puts "C: create U: update D: delete E: error"
|
10
10
|
puts ""
|
@@ -14,7 +14,7 @@ module Autosftp
|
|
14
14
|
|
15
15
|
update do |base, file|
|
16
16
|
begin
|
17
|
-
Autosftp::Connection.create setting, "#{base}/#{file}", "#{setting[:remote_path]}/#{file}"
|
17
|
+
Autosftp::Connection.create setting, "#{base}/#{file}", "#{setting[:remote_path]}/#{file}", permission
|
18
18
|
puts "U: #{Time.now} #{setting[:remote_path]}/#{file}"
|
19
19
|
rescue
|
20
20
|
puts "EU: #{Time.now} #{setting[:remote_path]}/#{file}"
|
@@ -23,7 +23,7 @@ module Autosftp
|
|
23
23
|
|
24
24
|
create do |base, file|
|
25
25
|
begin
|
26
|
-
Autosftp::Connection.create setting, "#{base}/#{file}", "#{setting[:remote_path]}/#{file}"
|
26
|
+
Autosftp::Connection.create setting, "#{base}/#{file}", "#{setting[:remote_path]}/#{file}", permission
|
27
27
|
puts "C: #{Time.now} #{setting[:remote_path]}/#{file}"
|
28
28
|
rescue
|
29
29
|
puts "EC: #{Time.now} #{setting[:remote_path]}/#{file}"
|
data/lib/autosftp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autosftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirabaru
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|