File tree Expand file tree Collapse file tree 6 files changed +56
-4
lines changed Expand file tree Collapse file tree 6 files changed +56
-4
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,14 @@ gem 'rails', '~> 7.1.3'
66
77gem 'aws-sdk-s3'
88gem 'base62-rb'
9+ gem 'bcrypt_pbkdf'
910gem 'bootsnap' , require : false
11+ gem 'ed25519'
1012gem 'faraday'
1113gem 'faraday-multipart'
1214gem 'jb'
1315gem 'metabobank_tools' , github : 'ddbj/metabobank_tools'
16+ gem 'net-sftp' , require : 'net/sftp'
1417gem 'noodles_gff' , path : '../noodles_gff-rb'
1518gem 'openid_connect'
1619gem 'pagy'
Original file line number Diff line number Diff line change 123123 aws-eventstream (~> 1 , >= 1.0.2 )
124124 base62-rb (0.3.1 )
125125 base64 (0.2.0 )
126+ bcrypt_pbkdf (1.1.1 )
127+ bcrypt_pbkdf (1.1.1-arm64-darwin )
126128 bigdecimal (3.1.8 )
127129 bindata (2.5.0 )
128130 bootsnap (1.18.3 )
142144 reline (>= 0.3.8 )
143145 diff-lcs (1.5.1 )
144146 drb (2.2.1 )
147+ ed25519 (1.3.0 )
145148 email_validator (2.2.4 )
146149 activemodel
147150 erubi (1.13.0 )
210213 net-protocol
211214 net-protocol (0.2.2 )
212215 timeout
216+ net-sftp (4.0.0 )
217+ net-ssh (>= 5.0.0 , < 8.0.0 )
213218 net-smtp (0.5.0 )
214219 net-protocol
220+ net-ssh (7.2.3 )
215221 nio4r (2.7.3 )
216222 nokogiri (1.16.6-aarch64-linux )
217223 racc (~> 1.4 )
@@ -396,14 +402,17 @@ PLATFORMS
396402DEPENDENCIES
397403 aws-sdk-s3
398404 base62-rb
405+ bcrypt_pbkdf
399406 bootsnap
400407 climate_control
401408 debug
409+ ed25519
402410 factory_bot_rails
403411 faraday
404412 faraday-multipart
405413 jb
406414 metabobank_tools !
415+ net-sftp
407416 noodles_gff !
408417 openid_connect
409418 pagy
Original file line number Diff line number Diff line change @@ -95,6 +95,26 @@ def submit(submission)
9595 ext_id : ,
9696 submitter_id :
9797 )
98+
99+ Net ::SFTP . start 'localhost' , 'maimu' , key_data : [ File . read ( '/Users/maimu/.ssh/id_ed25519_no_passphrase' ) ] do |sftp |
100+ mkdir_p! sftp , 'Documents/upload/foo/bar'
101+ end
102+ end
103+
104+ private
105+
106+ def mkdir_p! ( sftp , path )
107+ components = path . split ( '/' )
108+
109+ components . size . times . map { |i |
110+ components [ 0 ..i ] . join ( '/' )
111+ } . each do |sub_path |
112+ begin
113+ sftp . mkdir! sub_path
114+ rescue Net ::SFTP ::StatusException => e
115+ raise unless e . code == 4
116+ end
117+ end
98118 end
99119 end
100120 end
Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ source 'https://rubygems.org'
22
33gem 'bcrypt_pbkdf'
44gem 'ed25519'
5- gem 'net-ssh '
5+ gem 'net-sftp' , require : 'net/sftp '
66gem 'pg'
77gem 'sequel'
Original file line number Diff line number Diff line change 44 bcrypt_pbkdf (1.1.1 )
55 bigdecimal (3.1.8 )
66 ed25519 (1.3.0 )
7+ net-sftp (4.0.0 )
8+ net-ssh (>= 5.0.0 , < 8.0.0 )
79 net-ssh (7.2.3 )
810 pg (1.5.6 )
911 sequel (5.81.0 )
@@ -16,7 +18,7 @@ PLATFORMS
1618DEPENDENCIES
1719 bcrypt_pbkdf
1820 ed25519
19- net-ssh
21+ net-sftp
2022 pg
2123 sequel
2224
Original file line number Diff line number Diff line change 88
99# submissions.insert usr_id: 42, submitter_id: '42', serial: 42
1010
11- Net ::SSH . start 'localhost' , 'ursm' , key_data : [ File . read ( '/home/ursm/.ssh/id_25519_no_passphrase' ) ] do |ssh |
12- puts ssh . exec! ( 'uname -a' )
11+ # ディレクトリ名を引数で受け取れるようにする
12+ # 受け取った引数を元に再帰的にディレクトリを作成するメソッドを一つ用意する
13+ # そのメソッドの中で例外処理をする
14+
15+ def mkdir_p! ( sftp , dir )
16+ dir_names = dir . split ( '/' )
17+
18+ dir_names . size . times . map { |i |
19+ dir_names [ 0 ..i ] . join ( '/' )
20+ } . each do |dir_name |
21+ begin
22+ sftp . mkdir! dir_name
23+ rescue Net ::SFTP ::StatusException => e
24+ raise unless e . code == 4
25+ end
26+ end
27+ end
28+
29+ Net ::SFTP . start 'localhost' , 'maimu' , key_data : [ File . read ( '/Users/maimu/.ssh/id_ed25519_no_passphrase' ) ] do |sftp |
30+ mkdir_p! ( sftp , 'Documents/upload/foo/bar' )
1331end
You can’t perform that action at this time.
0 commit comments