Class: LibSSH::Scp

Inherits:
Object
  • Object
show all
Defined in:
ext/libssh_ruby/scp.c,
ext/libssh_ruby/scp.c

Overview

Wrapper for ssh_scp struct in libssh.

Constant Summary collapse

REQUEST_NEWFILE =

See Also:

Since:

  • 0.2.0

INT2FIX(SSH_SCP_REQUEST_NEWFILE)
REQUEST_NEWDIR =

See Also:

Since:

  • 0.2.0

INT2FIX(SSH_SCP_REQUEST_NEWDIR)
REQUEST_ENDDIR =

See Also:

Since:

  • 0.2.0

INT2FIX(SSH_SCP_REQUEST_ENDDIR)
REQUEST_WARNING =

See Also:

Since:

  • 0.2.0

INT2FIX(SSH_SCP_REQUEST_WARNING)
REQUEST_EOF =

See Also:

Since:

  • 0.2.0

INT2FIX(SSH_SCP_REQUEST_EOF)

Instance Method Summary collapse

Constructor Details

#initialize(session, mode, path) ⇒ Scp

Create a new scp session.

See Also:

Since:

  • 0.2.0



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'ext/libssh_ruby/scp.c', line 63

static VALUE m_initialize(VALUE self, VALUE session, VALUE mode, VALUE path) {
  ScpHolder *holder;
  SessionHolder *session_holder;
  char *c_path;
  ID id_mode;
  int c_mode;

  Check_Type(mode, T_SYMBOL);
  id_mode = SYM2ID(mode);
  if (id_mode == id_read) {
    c_mode = SSH_SCP_READ;
  } else if (id_mode == id_write) {
    c_mode = SSH_SCP_WRITE;
  } else {
    rb_raise(rb_eArgError, "Invalid mode value: %" PRIsVALUE, mode);
  }
  c_path = StringValueCStr(path);
  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  session_holder = libssh_ruby_session_holder(session);
  holder->scp = ssh_scp_new(session_holder->session, c_mode, c_path);
  holder->session = session;

  return self;
}

Instance Method Details

#accept_requestnil

Accepts transfer of a file or creation of a directory coming from the remote party.

Since:

  • 0.2.0



303
304
305
306
307
308
309
310
311
312
# File 'ext/libssh_ruby/scp.c', line 303

static VALUE m_accept_request(VALUE self) {
  ScpHolder *holder;
  struct nogvl_scp_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  args.scp = holder->scp;
  rb_thread_call_without_gvl(nogvl_accept_request, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);
  return Qnil;
}

#closenil

Close the scp channel.

See Also:

Since:

  • 0.2.0



104
105
106
107
108
109
110
111
112
113
114
# File 'ext/libssh_ruby/scp.c', line 104

static VALUE m_close(VALUE self) {
  ScpHolder *holder;
  struct nogvl_scp_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  args.scp = holder->scp;
  rb_thread_call_without_gvl(nogvl_close, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);

  return Qnil;
}

#deny_requestnil

Deny the transfer of a file or creation of a directory coming from the remote party.

Since:

  • 0.2.0



333
334
335
336
337
338
339
340
341
342
343
# File 'ext/libssh_ruby/scp.c', line 333

static VALUE m_deny_request(VALUE self, VALUE reason) {
  ScpHolder *holder;
  struct nogvl_deny_request_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  args.scp = holder->scp;
  args.reason = StringValueCStr(reason);
  rb_thread_call_without_gvl(nogvl_deny_request, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);
  return Qnil;
}

#init {|scp| ... } ⇒ Object

Initialize the scp channel.

Yield Parameters:

  • scp (Scp)

    self

See Also:

Since:

  • 0.2.0



128
129
130
131
132
133
134
135
136
137
138
# File 'ext/libssh_ruby/scp.c', line 128

static VALUE m_init(VALUE self) {
  ScpHolder *holder;
  struct nogvl_scp_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  args.scp = holder->scp;
  rb_thread_call_without_gvl(nogvl_init, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);

  return rb_ensure(rb_yield, Qnil, m_close, self);
}

#pull_requestFixnum

Wait for a scp request.

Since:

  • 0.2.0



228
229
230
231
232
233
234
235
236
237
# File 'ext/libssh_ruby/scp.c', line 228

static VALUE m_pull_request(VALUE self) {
  ScpHolder *holder;
  struct nogvl_scp_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  args.scp = holder->scp;
  rb_thread_call_without_gvl(nogvl_pull_request, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);
  return INT2FIX(args.rc);
}

#push_file(filename, size, mode) ⇒ nil

Initialize the sending of a file to a scp in sink mode.

Since:

  • 0.2.0



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'ext/libssh_ruby/scp.c', line 164

static VALUE m_push_file(VALUE self, VALUE filename, VALUE size, VALUE mode) {
  ScpHolder *holder;
  struct nogvl_push_file_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  args.scp = holder->scp;
  args.filename = StringValueCStr(filename);
  args.size = NUM2ULONG(size);
  args.mode = FIX2INT(mode);
  rb_thread_call_without_gvl(nogvl_push_file, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);
  return Qnil;
}

#read(size) ⇒ String

Read from a remote scp file.

See Also:

Since:

  • 0.2.0



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'ext/libssh_ruby/scp.c', line 364

static VALUE m_read(VALUE self, VALUE size) {
  ScpHolder *holder;
  struct nogvl_read_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  Check_Type(size, T_FIXNUM);
  args.scp = holder->scp;
  args.size = FIX2INT(size);
  args.buffer = ALLOC_N(char, args.size);
  rb_thread_call_without_gvl(nogvl_read, &args, RUBY_UBF_IO, NULL);
  if (args.rc == SSH_ERROR) {
    ruby_xfree(args.buffer);
    RAISE_IF_ERROR(args.rc);
    return Qnil; /* unreachable */
  } else {
    VALUE ret = rb_utf8_str_new(args.buffer, args.rc);
    ruby_xfree(args.buffer);
    return ret;
  }
}

#request_filenameString?

Get the name of the directory or file being pushed from the other party.

Since:

  • 0.2.0



260
261
262
263
264
265
266
267
268
269
270
271
# File 'ext/libssh_ruby/scp.c', line 260

static VALUE m_request_filename(VALUE self) {
  ScpHolder *holder;
  const char *filename;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  filename = ssh_scp_request_get_filename(holder->scp);
  if (filename == NULL) {
    return Qnil;
  } else {
    return rb_str_new_cstr(filename);
  }
}

#request_permissionsFixnum

Get the permissions of the directory or file being pushed from the other party.

Since:

  • 0.2.0



280
281
282
283
284
285
286
287
288
# File 'ext/libssh_ruby/scp.c', line 280

static VALUE m_request_permissions(VALUE self) {
  ScpHolder *holder;
  int mode;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  mode = ssh_scp_request_get_permissions(holder->scp);
  RAISE_IF_ERROR(mode);
  return INT2FIX(mode);
}

#request_sizeInteger

Get the size of the file being pushed from the other party.

Since:

  • 0.2.0



245
246
247
248
249
250
251
252
# File 'ext/libssh_ruby/scp.c', line 245

static VALUE m_request_size(VALUE self) {
  ScpHolder *holder;
  uint64_t size;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  size = ssh_scp_request_get_size64(holder->scp);
  return ULL2NUM(size);
}

#request_warningString?

Get the warning string.

Since:

  • 0.2.0



391
392
393
394
395
396
397
398
399
400
401
402
# File 'ext/libssh_ruby/scp.c', line 391

static VALUE m_request_warning(VALUE self) {
  ScpHolder *holder;
  const char *warning;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  warning = ssh_scp_request_get_warning(holder->scp);
  if (warning == NULL) {
    return Qnil;
  } else {
    return rb_str_new_cstr(warning);
  }
}

#write(data) ⇒ nil

Write into a remote scp file.

See Also:

Since:

  • 0.2.0



197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'ext/libssh_ruby/scp.c', line 197

static VALUE m_write(VALUE self, VALUE data) {
  ScpHolder *holder;
  struct nogvl_write_args args;

  TypedData_Get_Struct(self, ScpHolder, &scp_type, holder);
  Check_Type(data, T_STRING);
  args.scp = holder->scp;
  args.buffer = RSTRING_PTR(data);
  args.len = RSTRING_LEN(data);
  rb_thread_call_without_gvl(nogvl_write, &args, RUBY_UBF_IO, NULL);
  RAISE_IF_ERROR(args.rc);
  return Qnil;
}