rncp 0.0.1 → 0.0.2

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.
@@ -0,0 +1 @@
1
+ --exclude .*_cmd.rb --exclude rncp.rb --no-private --protected lib/**/*.rb - README.md CHANGELOG
@@ -0,0 +1,6 @@
1
+ 0.0.2
2
+ - Added support for UDP Broadcast
3
+ - Added documentation
4
+
5
+ 0.0.1
6
+ - Initial release
@@ -0,0 +1,48 @@
1
+ rncp / Ruby Network Copy
2
+ ====
3
+
4
+ This project is a port of Pyncp which is a port of the original
5
+ "ncp - a fast file copy tool for LANs" originally written by Felix von
6
+ Leitner <felix-ncp@fefe.de>
7
+
8
+ At the moment rncp seems to be compatible with pyncp's default settings
9
+ (i.e. Multicast for poll/push and gzip compression) but all options
10
+ will eventually be implemented via command line arguments. Also, all
11
+ code should be pure ruby (minitar and Glib gems) so it should work with
12
+ most if not all OS's.
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Install ruby, then install the gem:
18
+
19
+ $ gem install rncp
20
+
21
+ Its a pure ruby gem, depending on pure ruby gems, so it should work with
22
+ most rubies.
23
+
24
+ Quick Start
25
+ -----------
26
+
27
+ If you want to send a file, directory or group of files/directories, start
28
+ the listener on the destination machine:
29
+
30
+ $ rncp
31
+
32
+ To send a file or directory directly:
33
+
34
+ $ rncp send 192.168.1.2 file.txt ./directory
35
+
36
+ To send files and directories without knowing IP Addresses or Hostnames
37
+ setup a Multicast/Broadcast Poll on the destination machine:
38
+
39
+ $ rncp poll
40
+
41
+ To send via Multicast/Broadcast use a push:
42
+
43
+ $ rncp push file.txt ./directory
44
+
45
+ Credits
46
+ -------
47
+ Thanks to [Felix](http://www.fefe.de/ncp/) and
48
+ [makefu](https://github.com/makefu/pyncp)
data/bin/rncp CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rncp'
4
-
5
- RNCP::Cli::CommandLineRunner.run
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rncp'
4
+
5
+ RNCP::Cli::CommandLineRunner.run
@@ -1,39 +1,44 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/version'
15
-
16
- require 'clamp'
17
-
18
- require 'rncp/listen_cmd'
19
- require 'rncp/send_cmd'
20
- require 'rncp/poll_cmd'
21
- require 'rncp/push_cmd'
22
-
23
- module RNCP
24
- def self.version_string
25
- "RNCP version #{RNCP::VERSION}"
26
- end
27
-
28
- module Cli
29
- class CommandLineRunner < Clamp::Command
30
- self.default_subcommand = "listen"
31
-
32
- subcommand 'listen', "runs in listener mode, waits for connection", ListenCommand
33
- subcommand 'send', "sends files to a listener mode receiver", SendCommand
34
- subcommand 'push', "broadcasts for clients, waits for connection", PushCommand
35
- subcommand 'poll', "waits for broadcast, connects to broadcaster", PollCommand
36
- end
37
- end # Cli
38
- end
39
-
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/version'
15
+
16
+ require 'clamp'
17
+
18
+ require 'rncp/listen_cmd'
19
+ require 'rncp/send_cmd'
20
+ require 'rncp/poll_cmd'
21
+ require 'rncp/push_cmd'
22
+
23
+ module RNCP
24
+ def self.version_string
25
+ "rncp version #{RNCP::VERSION}"
26
+ end
27
+
28
+ module Cli
29
+ class CommandLineRunner < Clamp::Command
30
+ self.default_subcommand = "listen"
31
+
32
+ option ["--version", "-v"], :flag, "Show version" do
33
+ puts "rncp version #{RNCP::VERSION}"
34
+ exit(0)
35
+ end
36
+
37
+ subcommand 'listen', "runs in listener mode, waits for connection", ListenCommand
38
+ subcommand 'send', "sends files to a listener mode receiver", SendCommand
39
+ subcommand 'push', "broadcasts for clients, waits for connection", PushCommand
40
+ subcommand 'poll', "waits for broadcast, connects to broadcaster", PollCommand
41
+ end
42
+ end # Cli
43
+ end
44
+
@@ -1,65 +1,78 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'zlib'
15
- require 'archive/tar/minitar'
16
- require 'stringio'
17
-
18
- module RNCP
19
- module Files
20
- def directory_list(path)
21
- return [path].flatten if File.directory?(path) == false
22
-
23
- data = []
24
- Dir["#{path}**/*", "#{path}**/.*"].each do |entry|
25
- next if entry[/^.*\/\.+$/]
26
- data << directory_list(entry)
27
- end
28
- return data.flatten
29
- end # directory_list
30
-
31
- def tar(files)
32
- data = StringIO.new("")
33
- sgz = Zlib::GzipWriter.new(data)
34
- tar = Archive::Tar::Minitar::Output.new sgz
35
-
36
- puts "[#] start writing files"
37
- files.each do |f|
38
- directory_list(f).each do |entry|
39
- puts "[*] adding: #{entry}"
40
- Archive::Tar::Minitar.pack_file(entry, tar)
41
- end
42
- end
43
-
44
- sgz.flush
45
- sgz.close
46
- sgz = nil
47
-
48
- data.rewind
49
- return data
50
- end # tar
51
-
52
- def untar(data)
53
- sgz = Zlib::GzipReader.new(StringIO.new(data))
54
- tar = Archive::Tar::Minitar::Input.new sgz
55
-
56
- tar.each do |entry|
57
- puts "[*] #{entry.name}"
58
- tar.extract_entry "./", entry
59
- end
60
-
61
- sgz.close
62
- end # untar
63
-
64
- end # Files
65
- end # RNCP
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'zlib'
15
+ require 'archive/tar/minitar'
16
+ require 'stringio'
17
+
18
+ module RNCP
19
+ # Module containing functions related to the file system and archive
20
+ # compression/decompression.
21
+ module Files
22
+ # Recursively creates a list of all items (files/directories) found
23
+ # in the path.
24
+ # @param path [String] path to starting directory or file
25
+ # @return [Array] flatten array of all contents of directory, or file
26
+ def directory_list(path)
27
+ return [path].flatten if File.directory?(path) == false
28
+
29
+ data = []
30
+ Dir["#{path}**/*", "#{path}**/.*"].each do |entry|
31
+ next if entry[/^.*\/\.+$/]
32
+ data << directory_list(entry)
33
+ end
34
+ return data.flatten
35
+ end # directory_list
36
+
37
+ # Creates a data string of a tar gzip file containing all files in
38
+ # list. See {#untar} for decompression.
39
+ # @param files [Arrray] list of files to add to archive
40
+ # return [StringIO] data bytes of tar gzip archive.
41
+ def tar(files)
42
+ data = StringIO.new("")
43
+ sgz = Zlib::GzipWriter.new(data)
44
+ tar = Archive::Tar::Minitar::Output.new sgz
45
+
46
+ puts "[#] start writing files"
47
+ files.each do |f|
48
+ directory_list(f).each do |entry|
49
+ puts "[*] adding: #{entry}"
50
+ Archive::Tar::Minitar.pack_file(entry, tar)
51
+ end
52
+ end
53
+
54
+ sgz.flush
55
+ sgz.close
56
+ sgz = nil
57
+
58
+ data.rewind
59
+ return data
60
+ end # tar
61
+
62
+ # Decompresses a data string of a tar gzip archive to current working
63
+ # directory. See {#tar} for compression.
64
+ # @param data [String] data bytes of tar gzip archive
65
+ def untar(data)
66
+ sgz = Zlib::GzipReader.new(StringIO.new(data))
67
+ tar = Archive::Tar::Minitar::Input.new sgz
68
+
69
+ tar.each do |entry|
70
+ puts "[*] #{entry.name}"
71
+ tar.extract_entry "./", entry
72
+ end
73
+
74
+ sgz.close
75
+ end # untar
76
+
77
+ end # Files
78
+ end # RNCP
@@ -1,26 +1,26 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/listener'
15
-
16
- module RNCP
17
- module Cli
18
- class ListenCommand < Clamp::Command
19
-
20
- def execute
21
- RNCP::NcpListener.new.listen
22
- end
23
-
24
- end # ListenCommand
25
- end # Cli
26
- end # RNCP
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/listener'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class ListenCommand < Clamp::Command
19
+
20
+ def execute
21
+ RNCP::NcpListener.new.listen
22
+ end
23
+
24
+ end # ListenCommand
25
+ end # Cli
26
+ end # RNCP
@@ -1,84 +1,102 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/networking'
15
- require 'rncp/files'
16
-
17
- module RNCP
18
- class NcpListener
19
- include RNCP::Networking
20
- include RNCP::Files
21
-
22
- def initialize
23
- end
24
-
25
- def listen
26
- puts "[#] rncp Listener: creating new connection"
27
- l = bind_tcp
28
- puts "[*] waiting for connections"
29
-
30
- sock, info = l.accept
31
- printf "[*] connection from %s:%s\n", info.ip_address, info.ip_port
32
- puts "[*] receiving..."
33
-
34
- data = ""
35
- while (sock.eof? == false)
36
- data += sock.gets()
37
- end
38
-
39
- untar data
40
- puts "[*] received: "
41
-
42
- puts "[#] finished"
43
- sock.close
44
- l.close
45
- end # listen
46
-
47
- def poll
48
- addr = nil
49
- msock = join_multicast
50
- puts "[*] waiting for something-cast"
51
- loop do
52
- begin
53
- data, addr = msock.recvfrom 1024
54
- if addr[1] == RNCP::PORT
55
- puts "[*] found pusher at #{addr[3]}:#{addr[1]}"
56
- puts "[#] Anouncement: #{data}"
57
- break
58
- else
59
- puts "[?] received garbase from #{addr}"
60
- end
61
- rescue Execeptione => e
62
- puts "exception #{e}"
63
- end # begin
64
- end #loop
65
-
66
- msock.close if msock.nil? == false
67
-
68
- sock = TCPSocket::new addr[3], addr[1]
69
- sock.send "I am ready!", 0
70
-
71
- data = ""
72
- while (sock.eof? == false)
73
- data += sock.gets()
74
- end
75
-
76
- untar data
77
- puts "[*] received: "
78
-
79
- puts "[#] finished"
80
- sock.close
81
- end # poll
82
-
83
- end # NcpListener
84
- end # RNCP
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/networking'
15
+ require 'rncp/files'
16
+
17
+ module RNCP
18
+ # Class used to listen for direct and Multicast/Broadcast connections,
19
+ # which then triggers the receving of data from the Pusher class.
20
+ class NcpListener
21
+ include RNCP::Networking
22
+ include RNCP::Files
23
+
24
+ def initialize
25
+ end
26
+
27
+ # Listens for a direct connection from a source. Will wait until
28
+ # a connection is made and then decompresses files to current
29
+ # working directory.
30
+ def listen
31
+ puts "[#] rncp Listener: creating new connection"
32
+ l = bind_tcp
33
+ puts "[*] waiting for connections"
34
+
35
+ sock, info = l.accept
36
+ printf "[*] connection from %s:%s\n", info.ip_address, info.ip_port
37
+ puts "[*] receiving..."
38
+
39
+ data = ""
40
+ while (sock.eof? == false)
41
+ data += sock.gets()
42
+ end
43
+
44
+ untar data
45
+ puts "[*] received: "
46
+
47
+ puts "[#] finished"
48
+ sock.close
49
+ l.close
50
+ end # listen
51
+
52
+ # Waits for a Multicast or Broadcast message sent by a source and
53
+ # establishes a connection similar to {#listen} which then
54
+ # decompresses files to current working directory.
55
+ def poll
56
+ addr = nil
57
+ msock = join_multicast
58
+ bsock = bind_broadcast
59
+
60
+ if msock.nil? == true && bsock.nil? == true
61
+ puts "[!] cannot continue without atleast one announcement socket!"
62
+ return 1
63
+ end
64
+
65
+ xsock = msock.nil? == false ? msock : bsock
66
+
67
+ puts "[*] waiting for something-cast"
68
+ loop do
69
+ begin
70
+ data, addr = xsock.recvfrom 1024
71
+ if addr[1] == RNCP::PORT
72
+ puts "[*] found pusher at #{addr[3]}:#{addr[1]}"
73
+ puts "[#] Anouncement: #{data}"
74
+ break
75
+ else
76
+ puts "[?] received garbase from #{addr}"
77
+ end
78
+ rescue Exception => e
79
+ puts "exception #{e}"
80
+ end # begin
81
+ end #loop
82
+
83
+ msock.close if msock.nil? == false
84
+ bsock.close if bsock.nil? == false
85
+
86
+ sock = TCPSocket::new addr[3], addr[1]
87
+ sock.send "I am ready!", 0
88
+
89
+ data = ""
90
+ while (sock.eof? == false)
91
+ data += sock.gets()
92
+ end
93
+
94
+ untar data
95
+ puts "[*] received: "
96
+
97
+ puts "[#] finished"
98
+ sock.close
99
+ end # poll
100
+
101
+ end # NcpListener
102
+ end # RNCP
@@ -1,54 +1,91 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'socket'
15
- require 'ipaddr'
16
- require 'rncp/params'
17
-
18
- module RNCP
19
- module Networking
20
- def bind_tcp
21
- sock = Socket::new Socket::AF_INET, Socket::SOCK_STREAM, 0
22
- opts = [1].pack("i")
23
- addr = [Socket::AF_INET, RNCP::PORT, 0, 0, 0, 0, 0, 0]
24
- .pack("snCCCCNN")
25
-
26
- sock.setsockopt Socket::SOL_SOCKET, Socket::SO_REUSEADDR, opts
27
- sock.bind addr
28
- sock.listen 1
29
- return sock
30
- end # bind_tcp
31
-
32
- def join_multicast
33
- msock = UDPSocket.new
34
- membership = IPAddr.new(RNCP::IPV4_GROUP).hton +
35
- IPAddr.new("0.0.0.0").hton
36
-
37
- puts "[#] Joining Multicast group"
38
- msock.setsockopt :IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership
39
- msock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
40
- msock.bind "0.0.0.0", RNCP::PORT
41
-
42
- return msock
43
- end # join_multicast
44
-
45
- def bind_multicast
46
- msock = UDPSocket.open
47
- msock.setsockopt :IPPROTO_IP, :IP_MULTICAST_TTL, [32].pack("i")
48
- msock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
49
- msock.bind '', RNCP::PORT
50
- msock.setsockopt :IPPROTO_IP, :IP_MULTICAST_LOOP, 1
51
- return msock
52
- end # bind_multicast
53
- end # Networking
54
- end # RNCP
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'socket'
15
+ require 'ipaddr'
16
+ require 'rncp/params'
17
+
18
+ module RNCP
19
+ # Contains common networking operations shared between listeners and
20
+ # pushers.
21
+ module Networking
22
+ # Creates a TCP connection to listen for direct connections
23
+ # @return [Socket] listening socket
24
+ def bind_tcp
25
+ sock = Socket::new Socket::AF_INET, Socket::SOCK_STREAM, 0
26
+ opts = [1].pack("i")
27
+ addr = [Socket::AF_INET, RNCP::PORT, 0, 0, 0, 0, 0, 0]
28
+ .pack("snCCCCNN")
29
+
30
+ sock.setsockopt Socket::SOL_SOCKET, Socket::SO_REUSEADDR, opts
31
+ sock.bind addr
32
+ sock.listen 1
33
+ return sock
34
+ end # bind_tcp
35
+
36
+ # Creates a socket bound to the Multicast group. Returns nil if fails.
37
+ # This socket is used to listen for messages sent via Multicast. See
38
+ # {#bind_multicast} to send.
39
+ # @return [UDPSocket] multicast socket
40
+ def join_multicast
41
+ begin
42
+ msock = UDPSocket.new
43
+ membership = IPAddr.new(RNCP::IPV4_GROUP).hton +
44
+ IPAddr.new("0.0.0.0").hton
45
+
46
+ puts "[#] Joining Multicast group"
47
+ msock.setsockopt :IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership
48
+ msock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
49
+ msock.bind "0.0.0.0", RNCP::PORT
50
+
51
+ return msock
52
+ rescue
53
+ puts "[!] Multicast not supported"
54
+ return nil
55
+ end
56
+ end # join_multicast
57
+
58
+ # Creates a socket that sends to Multicast group. Returns nil if fails.
59
+ # See {#join_multicast} to listen for Multicast.
60
+ # @return [UDPSocket] multicast socket
61
+ def bind_multicast
62
+ begin
63
+ msock = UDPSocket.open
64
+ msock.setsockopt :IPPROTO_IP, :IP_MULTICAST_TTL, [32].pack("i")
65
+ msock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
66
+ msock.bind '', RNCP::PORT
67
+ msock.setsockopt :IPPROTO_IP, :IP_MULTICAST_LOOP, 1
68
+ return msock
69
+ rescue
70
+ puts "[!] Multicast not supported"
71
+ return nil
72
+ end
73
+ end # bind_multicast
74
+
75
+ # Creates a socket that sends and receives via Broadcast address.
76
+ # Returns nil if fails.
77
+ # @return [UDPSocket] broadcast socket
78
+ def bind_broadcast
79
+ begin
80
+ bsock = UDPSocket.open
81
+ bsock.setsockopt :SOL_SOCKET, :SO_BROADCAST, 1
82
+ bsock.setsockopt :SOL_SOCKET, :SO_REUSEADDR, 1
83
+ bsock.bind '', RNCP::PORT
84
+ return bsock
85
+ rescue
86
+ puts "[!] Broadcast not supported"
87
+ return nil
88
+ end
89
+ end # bind_broadcast
90
+ end # Networking
91
+ end # RNCP
@@ -1,22 +1,31 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/version'
15
-
16
- module RNCP
17
- IPV4_GROUP = '224.110.99.112'
18
- IPV4_BC = '255.255.255.255'
19
- PORT = 8002
20
- MC_MSG = "Multicasting for rncp Version #{RNCP::VERSION}"
21
- BC_MSG = "Broadcasting for rncp Version #{RNCP::VERSION}"
22
- end
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/version'
15
+
16
+ module RNCP
17
+ # IPv4 Multicast Group
18
+ IPV4_GROUP = '224.110.99.112'
19
+
20
+ # IPv4 Broadcast Address
21
+ IPV4_BC = '255.255.255.255'
22
+
23
+ # ncp Server Port
24
+ PORT = 8002
25
+
26
+ # Message sent when connecting via multicast
27
+ MC_MSG = "Multicasting for rncp Version #{RNCP::VERSION}"
28
+
29
+ # Message sentw hen connecting via broadcast
30
+ BC_MSG = "Broadcasting for rncp Version #{RNCP::VERSION}"
31
+ end
@@ -1,27 +1,27 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/listener'
15
-
16
- module RNCP
17
- module Cli
18
- class PollCommand < Clamp::Command
19
-
20
- def execute
21
- RNCP::NcpListener.new.poll
22
- end
23
-
24
- end # PollCommand
25
- end # Cli
26
- end # RNCP
27
-
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/listener'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class PollCommand < Clamp::Command
19
+
20
+ def execute
21
+ RNCP::NcpListener.new.poll
22
+ end
23
+
24
+ end # PollCommand
25
+ end # Cli
26
+ end # RNCP
27
+
@@ -1,29 +1,29 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/pusher'
15
-
16
- module RNCP
17
- module Cli
18
- class PushCommand < Clamp::Command
19
-
20
- parameter "FILE ...", "Files to send"
21
-
22
- def execute
23
- RNCP::NcpPusher.new.push file_list
24
- end
25
-
26
- end # PushCommand
27
- end # Cli
28
- end # RNCP
29
-
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/pusher'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class PushCommand < Clamp::Command
19
+
20
+ parameter "FILE ...", "Files to send"
21
+
22
+ def execute
23
+ RNCP::NcpPusher.new.push file_list
24
+ end
25
+
26
+ end # PushCommand
27
+ end # Cli
28
+ end # RNCP
29
+
@@ -1,109 +1,127 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/networking'
15
- require 'stringio'
16
- require 'fileutils'
17
- require 'zlib'
18
- require 'archive/tar/minitar'
19
- require 'tempfile'
20
-
21
- module RNCP
22
- class NcpPusher
23
- include RNCP::Networking
24
- include RNCP::Files
25
-
26
- def initialize
27
- end
28
-
29
- def send_to(ip, files)
30
- begin
31
- puts "[*] copying #{files} to ip : #{ip}"
32
- sock = TCPSocket::new ip, RNCP::PORT
33
- sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
34
-
35
- data = tar files
36
-
37
- sock.send data.string, 0
38
- sock.flush
39
-
40
- rescue Exception => e
41
- puts "[!] cannot create connection to host, bailing out"
42
- puts e
43
- ensure
44
- sock.close if sock.nil? == false
45
- puts "[#] finished"
46
- end
47
- end # send_to
48
-
49
- def push(files)
50
- begin
51
- sock = nil
52
- addr = nil
53
- msock = bind_multicast
54
-
55
- # check broadcast
56
-
57
- if msock.nil? == true
58
- puts "[!] cannot continue without atleast one announcement socket!"
59
- return 1
60
- end
61
-
62
- dsock = bind_tcp
63
-
64
- if dsock.nil? == true
65
- puts "[!] cannot continue without data socket"
66
- return -1
67
- end
68
-
69
- puts "[*] starting X-Casting, waiting for TCP connect"
70
- while sock.nil? == true
71
- if msock.nil? == false
72
- msock.send RNCP::MC_MSG, 0, RNCP::IPV4_GROUP, RNCP::PORT
73
- end
74
- # Broadcast
75
- puts "."
76
- result = select( [dsock], nil, nil, 2 )
77
-
78
- next if result.nil? == true
79
- for inp in result[0]
80
- if inp == dsock
81
- sock, addr = dsock.accept
82
- printf "[*] connection from %s:%s\n",
83
- addr.ip_address, addr.ip_port
84
- puts "[*] Client answer: #{sock.recv 1024}"
85
- end # if
86
- end # for inp
87
- end # while sock.nil?
88
-
89
- msock.close if msock.nil? == false
90
- msock = nil
91
- dsock.close if dsock.nil? == false
92
- dsock = nil
93
-
94
- data = tar files
95
-
96
- sock.send data.string, 0
97
- sock.flush
98
- rescue Exception => e
99
- puts "[!] cannot push data, bailing out"
100
- puts e
101
- ensure
102
- sock.close if sock.nil? == false
103
- puts "[*] finished"
104
- msock.close if msock.nil? == false
105
- dsock.close if dsock.nil? == false
106
- end # begin
107
- end # push
108
- end # NcpPusher
109
- end # RNCP
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/networking'
15
+ require 'stringio'
16
+ require 'fileutils'
17
+ require 'zlib'
18
+ require 'archive/tar/minitar'
19
+ require 'tempfile'
20
+
21
+ module RNCP
22
+ # Class to establish a connection to a Listener class and then compress
23
+ # and send files.
24
+ class NcpPusher
25
+ include RNCP::Networking
26
+ include RNCP::Files
27
+
28
+ def initialize
29
+ end
30
+
31
+ # Sends file directly to a given IP Address or Hostname
32
+ # @param ip [String] the address or hostname of the destination
33
+ # @param files [Array] array of file/directory names to send
34
+ def send_to(ip, files)
35
+ begin
36
+ puts "[*] copying #{files} to ip : #{ip}"
37
+ sock = TCPSocket::new ip, RNCP::PORT
38
+ sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
39
+
40
+ data = tar files
41
+
42
+ sock.send data.string, 0
43
+ sock.flush
44
+
45
+ rescue Exception => e
46
+ puts "[!] cannot create connection to host, bailing out"
47
+ puts e
48
+ ensure
49
+ sock.close if sock.nil? == false
50
+ puts "[#] finished"
51
+ end
52
+ end # send_to
53
+
54
+ # Using Multicast or Broadcast, establishes a connection, compresses
55
+ # files and sends to destination.
56
+ # @param files [Array] array of file names to send
57
+ def push(files)
58
+ begin
59
+ sock = nil
60
+ addr = nil
61
+ msock = bind_multicast
62
+
63
+ # check broadcast
64
+ bsock = bind_broadcast
65
+
66
+ if msock.nil? == true && bsock.nil? == true
67
+ puts "[!] cannot continue without atleast one announcement socket!"
68
+ return 1
69
+ end
70
+
71
+ dsock = bind_tcp
72
+
73
+ if dsock.nil? == true
74
+ puts "[!] cannot continue without data socket"
75
+ return -1
76
+ end
77
+
78
+ puts "[*] starting X-Casting, waiting for TCP connect"
79
+ while sock.nil? == true
80
+ # Multicast Ping
81
+ if msock.nil? == false
82
+ msock.send RNCP::MC_MSG, 0, RNCP::IPV4_GROUP, RNCP::PORT
83
+ end
84
+
85
+ # Broadcast Ping
86
+ if bsock.nil? == false
87
+ bsock.send RNCP::BC_MSG, 0, RNCP::IPV4_BC, RNCP::PORT
88
+ end
89
+
90
+ puts "."
91
+ result = select( [dsock], nil, nil, 2 )
92
+
93
+ next if result.nil? == true
94
+ for inp in result[0]
95
+ if inp == dsock
96
+ sock, addr = dsock.accept
97
+ printf "[*] connection from %s:%s\n",
98
+ addr.ip_address, addr.ip_port
99
+ puts "[*] Client answer: #{sock.recv 1024}"
100
+ end # if
101
+ end # for inp
102
+ end # while sock.nil?
103
+
104
+ msock.close if msock.nil? == false
105
+ msock = nil
106
+ bsock.close if bsock.nil? == false
107
+ bsock = nil
108
+ dsock.close if dsock.nil? == false
109
+ dsock = nil
110
+
111
+ data = tar files
112
+
113
+ sock.send data.string, 0
114
+ sock.flush
115
+ rescue Exception => e
116
+ puts "[!] cannot push data, bailing out"
117
+ puts e
118
+ ensure
119
+ sock.close if sock.nil? == false
120
+ puts "[*] finished"
121
+ msock.close if msock.nil? == false
122
+ bsock.close if bsock.nil? == false
123
+ dsock.close if dsock.nil? == false
124
+ end # begin
125
+ end # push
126
+ end # NcpPusher
127
+ end # RNCP
@@ -1,30 +1,30 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- require 'rncp/pusher'
15
-
16
- module RNCP
17
- module Cli
18
- class SendCommand < Clamp::Command
19
-
20
- parameter "IP", "Destination IP Address"
21
- parameter "FILE ...", "Files to send"
22
-
23
- def execute
24
- RNCP::NcpPusher.new.send_to ip, file_list
25
- end
26
-
27
- end # ListenCommand
28
- end # Cli
29
- end # RNCP
30
-
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ require 'rncp/pusher'
15
+
16
+ module RNCP
17
+ module Cli
18
+ class SendCommand < Clamp::Command
19
+
20
+ parameter "IP", "Destination IP Address"
21
+ parameter "FILE ...", "Files to send"
22
+
23
+ def execute
24
+ RNCP::NcpPusher.new.send_to ip, file_list
25
+ end
26
+
27
+ end # ListenCommand
28
+ end # Cli
29
+ end # RNCP
30
+
@@ -1,17 +1,17 @@
1
- # RNCP - a fast file copy tool for LANs port in Ruby
2
- #
3
- # Copyright (c) 2013 Jeff Parent
4
- #
5
- # This program is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 2 of the License or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
-
15
- module RNCP
16
- VERSION = '0.0.1'
17
- end
1
+ # RNCP - a fast file copy tool for LANs port in Ruby
2
+ #
3
+ # Copyright (c) 2013 Jeff Parent
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 2 of the License or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ module RNCP
16
+ VERSION = '0.0.2'
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rncp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,11 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0.3'
46
- description: A port of NCP written in Ruby
46
+ description: ! 'rncp provides a fast way of transfering files between systems.
47
+
48
+ Its pure Ruby port of Pyncp/Ncp.
49
+
50
+ '
47
51
  email:
48
52
  - jecxjo@sdf.lonestar.org
49
53
  executables:
@@ -51,17 +55,20 @@ executables:
51
55
  extensions: []
52
56
  extra_rdoc_files: []
53
57
  files:
54
- - lib/rncp.rb
55
- - lib/rncp/params.rb
56
- - lib/rncp/listener.rb
57
58
  - lib/rncp/files.rb
58
- - lib/rncp/pusher.rb
59
+ - lib/rncp/listener.rb
59
60
  - lib/rncp/listen_cmd.rb
60
- - lib/rncp/poll_cmd.rb
61
- - lib/rncp/version.rb
62
- - lib/rncp/send_cmd.rb
63
61
  - lib/rncp/networking.rb
62
+ - lib/rncp/params.rb
63
+ - lib/rncp/poll_cmd.rb
64
+ - lib/rncp/pusher.rb
64
65
  - lib/rncp/push_cmd.rb
66
+ - lib/rncp/send_cmd.rb
67
+ - lib/rncp/version.rb
68
+ - lib/rncp.rb
69
+ - .yardopts
70
+ - README.md
71
+ - CHANGELOG
65
72
  - bin/rncp
66
73
  homepage: http://github.com/jecxjo/rncp
67
74
  licenses: []
@@ -83,8 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
90
  version: '0'
84
91
  requirements: []
85
92
  rubyforge_project:
86
- rubygems_version: 1.8.23
93
+ rubygems_version: 1.8.24
87
94
  signing_key:
88
95
  specification_version: 3
89
96
  summary: a fast file copy tool for LANs
90
97
  test_files: []
98
+ has_rdoc: