tcpfiletransfer 0.0.6 → 0.1.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/bin/sendfile +9 -2
- data/lib/filetransfer/ftserver.rb +2 -1
- data/lib/filetransfer/httpserver.rb +7 -1
- data/lib/filetransfer/server.rb +6 -1
- data/lib/filetransfer.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c7f4fef199c5858b707c3ff5cc74365fcf8c577a43ee6beed17842b315680a
|
4
|
+
data.tar.gz: 9251b887e474654b553bceada578c06308765f5dee659e8d51785fe659c7c200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99599794d083185fe86953e77497ecb22d138ed763032b5d15a2de3b5c7cbe2ed68e1e02ed0c8458b7e060d4cc3cad2b902a1882c81dbfc051bd77b85e0ab6f5
|
7
|
+
data.tar.gz: 16e268c86d36233496e1e3ebd933eb03c7d2829a302ef40ccdf8318f3995c1a43bac31837919b2407d7e65543c1f4b53e92acd6beb9587d5221d46223c3870bb
|
data/bin/sendfile
CHANGED
@@ -5,9 +5,14 @@ require "socket"
|
|
5
5
|
originalpath = ARGV[0] || `zenity --file-selection --title='Send File'`.chomp
|
6
6
|
exit(1) if (!ARGV[0] && $?.exitstatus == 1)
|
7
7
|
|
8
|
-
path = originalpath.gsub(" ", "`")
|
8
|
+
path = File.expand_path(originalpath).gsub(" ", "`")
|
9
9
|
name = originalpath.split("/").last.gsub(" ", "_")
|
10
10
|
|
11
|
+
if File.directory?(path)
|
12
|
+
`zenity --error --text="Error: #{path} is a folder." --no-wrap --title="Send File"`
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
|
11
16
|
recipient = ""
|
12
17
|
loop do
|
13
18
|
recipient = ARGV[1] || `zenity --text="Recipient\\n(Leave blank to search for available recipients)" --entry --title='Send File'`.chomp
|
@@ -24,8 +29,10 @@ loop do
|
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
32
|
+
recipient = IPSocket.getaddress(recipient)
|
33
|
+
|
27
34
|
server = TCPSocket.new("127.0.0.1", 8021)
|
28
|
-
server.puts "FTSUBMIT #{name} #{path}"
|
35
|
+
server.puts "FTSUBMIT #{name} #{path} #{recipient}"
|
29
36
|
fileid = server.gets
|
30
37
|
|
31
38
|
file_size = '%.2f' % (File.size(originalpath).to_f / 2**20)
|
@@ -13,9 +13,10 @@ module FileTransfer
|
|
13
13
|
def self.handle_file_submission(initdata, client)
|
14
14
|
filename = initdata[1]
|
15
15
|
filepath = initdata[2].gsub("`", " ")
|
16
|
+
dest_ip = initdata[3]
|
16
17
|
|
17
18
|
fileid = self.genfileid(6)
|
18
|
-
$active_transfers[?/ + fileid] = {name: filename, path: filepath}
|
19
|
+
$active_transfers[?/ + fileid] = {name: filename, path: filepath, dest_ip: dest_ip}
|
19
20
|
client.puts fileid
|
20
21
|
client.close
|
21
22
|
end
|
@@ -27,8 +27,14 @@ module FileTransfer
|
|
27
27
|
return
|
28
28
|
end
|
29
29
|
|
30
|
+
if client.peeraddr[2] != file[:dest_ip]
|
31
|
+
client.puts "HTTP/1.0 403\r\nContent-Type: text/plain\r\n\r\nRequest from forbidden IP."
|
32
|
+
client.close
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
30
36
|
`zenity --info --title="Transfer Accepted" --text="Your transfer to #{remote_hostname} has been accepted." --no-wrap`
|
31
|
-
client.puts "HTTP/1.0 200\r\nContent-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=\"#{file[:name]}\"\r\n\r\n#{
|
37
|
+
client.puts "HTTP/1.0 200\r\nContent-Length: #{File.size file[:path]}\r\nContent-Type: application/octet-stream\r\nContent-Disposition: attachment; filename=\"#{file[:name]}\"\r\n\r\n#{IO.binread(file[:path])}"
|
32
38
|
$active_transfers.delete(path)
|
33
39
|
client.close
|
34
40
|
end
|
data/lib/filetransfer/server.rb
CHANGED
@@ -15,7 +15,12 @@ module FileTransfer
|
|
15
15
|
elsif initdata[0] == "FTSEND"
|
16
16
|
FTserver.handle_client(initdata, client)
|
17
17
|
elsif initdata[0] == "FTSUBMIT"
|
18
|
-
|
18
|
+
if client.peeraddr[2] == "127.0.0.1"
|
19
|
+
FTserver.handle_file_submission(initdata, client)
|
20
|
+
else
|
21
|
+
client.puts "ERROR FILE_SUBMIT_NOTLOCAL"
|
22
|
+
client.close
|
23
|
+
end
|
19
24
|
else
|
20
25
|
client.close
|
21
26
|
end
|
data/lib/filetransfer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tcpfiletransfer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An easy way to transfer files over TCP between linux computers
|
14
14
|
email: matthias@matthiasclee.com
|