sftp_server 0.5.0 → 0.6.0
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 +14 -0
- data/lib/sftp_server/server.rb +47 -14
- data/lib/sftp_server/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: 445996399523862768032cf1c5792561c134ef29
|
4
|
+
data.tar.gz: f1b84c99308b24cd2403797ae69a2feb42856ad8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 917a9c983158448c44d5d240bab0fafd8002c7da1dad9f7b18a73630f74a3f7a8421fba51b881b0f3f7cfa01d3052e6b3febe956db242ee680dab08d040fdbac
|
7
|
+
data.tar.gz: d7f345a7112a144a2b2565099f501ae65476d311579fa0bd4d199d9edf8dd01ee5217e61b1def3959ec339eabb370b952d135b021b9f68c9e02c990382e8029f
|
data/README.md
CHANGED
@@ -6,6 +6,20 @@ Uses libssh via FFI to create an SFTP server. Useful for testing interactions wi
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
+
### Installing libssh
|
10
|
+
|
11
|
+
This gem was developed against libssh 0.6.3. It will **not work** when using an older version.
|
12
|
+
|
13
|
+
To install libssh using Homebrew on Mac OS X:
|
14
|
+
|
15
|
+
```
|
16
|
+
brew install libssh
|
17
|
+
```
|
18
|
+
|
19
|
+
~~To install on Ubuntu 12.04 or Ubuntu 14.04, you'll need to build the library from source, because the versions that are available in Ubuntu package repositories are too old.~~ To work on Linux, [a patched version of libssh is required](https://github.com/corgibytes/sftp_server/issues/1).
|
20
|
+
|
21
|
+
### Installing the gem
|
22
|
+
|
9
23
|
Add this line to your application's Gemfile:
|
10
24
|
|
11
25
|
```ruby
|
data/lib/sftp_server/server.rb
CHANGED
@@ -212,11 +212,27 @@ module SFTPServer
|
|
212
212
|
|
213
213
|
if @handles[long_dir_name] == :open
|
214
214
|
Dir.entries(long_dir_name).each do |entry|
|
215
|
+
file_stat = File.lstat(File.join(long_dir_name, entry))
|
216
|
+
|
217
|
+
attributes = SSH::API::SFTPAttributes.new
|
218
|
+
|
219
|
+
attributes[:flags] = 0
|
220
|
+
attributes[:flags] |= SSH::API::Attributes::SSH_FILEXFER_ATTR_SIZE
|
221
|
+
attributes[:size] = file_stat.size
|
222
|
+
attributes[:flags] |= SSH::API::Attributes::SSH_FILEXFER_ATTR_UIDGID
|
223
|
+
attributes[:uid] = file_stat.uid
|
224
|
+
attributes[:gid] = file_stat.gid
|
225
|
+
attributes[:flags] |= SSH::API::Attributes::SSH_FILEXFER_ATTR_PERMISSIONS
|
226
|
+
attributes[:permissions] = file_stat.mode
|
227
|
+
attributes[:flags] |= SSH::API::Attributes::SSH_FILEXFER_ATTR_ACMODTIME
|
228
|
+
attributes[:atime] = file_stat.atime.to_i
|
229
|
+
attributes[:mtime] = file_stat.mtime.to_i
|
230
|
+
|
215
231
|
SSH::API.sftp_reply_names_add(
|
216
232
|
client_message,
|
217
233
|
entry,
|
218
234
|
entry,
|
219
|
-
|
235
|
+
attributes.to_ptr
|
220
236
|
)
|
221
237
|
end
|
222
238
|
@handles[long_dir_name] = :read
|
@@ -232,6 +248,11 @@ module SFTPServer
|
|
232
248
|
long_dir_name = handle.read_string
|
233
249
|
log "long_dir_name: #{long_dir_name}"
|
234
250
|
|
251
|
+
entry = @handles[long_dir_name]
|
252
|
+
if entry.respond_to?(:close)
|
253
|
+
entry.close
|
254
|
+
end
|
255
|
+
|
235
256
|
@handles.delete(long_dir_name)
|
236
257
|
|
237
258
|
SSH::API.sftp_reply_status(client_message, SSH::API::SFTPStatus::SSH_FX_OK, 'Success')
|
@@ -361,6 +382,16 @@ module SFTPServer
|
|
361
382
|
file.write(buffer.read_string)
|
362
383
|
SSH::API.sftp_reply_status(client_message, SSH::API::SFTPStatus::SSH_FX_OK, 'Success')
|
363
384
|
end
|
385
|
+
when SSH::API::SFTPCommands::SSH_FXP_REMOVE
|
386
|
+
log 'remove'
|
387
|
+
|
388
|
+
file_name = SSH::API.sftp_client_message_get_filename(client_message)
|
389
|
+
long_file_name = File.expand_path(file_name)
|
390
|
+
log "long_file_name: #{long_file_name}"
|
391
|
+
|
392
|
+
File.unlink(long_file_name)
|
393
|
+
|
394
|
+
SSH::API.sftp_reply_status(client_message, SSH::API::SFTPStatus::SSH_FX_OK, 'Success')
|
364
395
|
end
|
365
396
|
|
366
397
|
SSH::API.sftp_client_message_free(client_message)
|
@@ -389,7 +420,6 @@ module SFTPServer
|
|
389
420
|
|
390
421
|
def open
|
391
422
|
ssh_bind = SSH::API.ssh_bind_new
|
392
|
-
session = SSH::API.ssh_new
|
393
423
|
|
394
424
|
set_bind_option(ssh_bind, :int, SSH::API::BindOptions::SSH_BIND_OPTIONS_BINDADDR, :string, listen_address) if listen_address
|
395
425
|
set_bind_option(ssh_bind, :int, SSH::API::BindOptions::SSH_BIND_OPTIONS_BINDPORT_STR, :string, port) if port
|
@@ -397,20 +427,23 @@ module SFTPServer
|
|
397
427
|
set_bind_option(ssh_bind, :int, SSH::API::BindOptions::SSH_BIND_OPTIONS_DSAKEY, :string, dsa_key) if dsa_key
|
398
428
|
|
399
429
|
bind_listen(ssh_bind)
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
if
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
430
|
+
loop do
|
431
|
+
session = SSH::API.ssh_new
|
432
|
+
bind_accept(ssh_bind, session)
|
433
|
+
handle_key_exchange(session)
|
434
|
+
|
435
|
+
if authenticate(session)
|
436
|
+
channel = open_channel(session)
|
437
|
+
if channel
|
438
|
+
if sftp_channel_request(session)
|
439
|
+
sftp_session = SSH::API.sftp_server_new(session, channel)
|
440
|
+
init_sftp_session(sftp_session)
|
441
|
+
sftp_message_loop(sftp_session)
|
442
|
+
end
|
410
443
|
end
|
444
|
+
close_channel(channel)
|
445
|
+
free_channel(channel)
|
411
446
|
end
|
412
|
-
close_channel(channel)
|
413
|
-
free_channel(channel)
|
414
447
|
end
|
415
448
|
end
|
416
449
|
end
|
data/lib/sftp_server/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sftp_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M. Scott Ford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|