Class: Spitfire::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/spitfire.rb

Instance Method Summary collapse

Instance Method Details

#transferObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/spitfire.rb', line 44

def transfer
	source_user = options['source_user']
	source_user ||= %x[whoami].strip

	destination_user = options['destination_user']
	destination_user ||= source_user

	puts "Connecting to destination: #{options.destination_host} as #{destination_user}"
	destThread = Thread.new {
		destination = Net::SSH.start(options.destination_host, destination_user)
	    destChannel = channel_execute(
	      destination, 
	      "echo 'ok'; mkdir -p #{options.destination_dir}; cd #{options.destination_dir}; nc -vl #{options.port_number} | tar xvvf -", 
	      'DEST'
	    )
		destination.loop{true}
	}


	sleep(2)
	puts "Connecting to source: #{options.source_host} as #{source_user}"
	srcThread = Thread.new {
		source = Net::SSH.start(options.source_host, source_user) 
		command = "echo 'ok'; cd #{options.source_dir}; tar vvc . | nc -v #{options.destination_host} #{options.port_number}"
    
	    srcChannel = channel_execute(
	      source,
	      command,
	      ' SRC'
	    )
		source.close()
	}


	# wait for the source to finish
	srcThread.join

	# okay, now pause and kill the destination
	sleep(2)
	destThread.kill
end