Coder Social home page Coder Social logo

sdushantha / qr-filetransfer Goto Github PK

View Code? Open in Web Editor NEW
964.0 24.0 77.0 190 KB

Transfer files over WiFi between your computer and your smartphone from the terminal

Home Page: https://git.io/qr-filetransfer

License: MIT License

Python 100.00%
file-sharing qrcode mobile terminal python qr-filetransfer command-line-tool smartphone transfer wifi

qr-filetransfer's People

Contributors

cedarctic avatar gomercin avatar gurnec avatar imba-tjd avatar imgbotapp avatar npes87184 avatar orthdron avatar renzihou avatar sdushantha avatar therefromhere avatar thomas154 avatar weary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qr-filetransfer's Issues

Not Downloading

When I try to send .txt and image and some other files, it is displaying instead of downloading.

Remove -f flag?

Should we remove the -f flag?

So instead of:

python3 qr-filetransfer.py -f path/to/file

We can have:

python3 qr-filetransfer.py path/to/file

In my opinion, I am kind of fed up of typing -f.

UnicodeDecodeError when trying to upload an file

I am getting an error when I run

$ python3 qr-filetransfer -r ~/Downloads/ -debug
10.0.0.4 - - [01/May/2019 09:27:05] "GET / HTTP/1.1" 200 -
10.0.0.4 - - [01/May/2019 09:27:05] "GET /favicon.ico HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('10.0.0.4', 53764)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 720, in __init__
    self.handle()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 426, in handle
    self.handle_one_request()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 414, in handle_one_request
    method()
  File "qr-filetransfer", line 64, in do_POST
    r, info = self.deal_post_data()
  File "qr-filetransfer", line 108, in deal_post_data
    fn = re.findall(r'Content-Disposition.*name="file"; filename="(.*)"', line.decode())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 71: invalid start byte
----------------------------------------

@npes87184 Do you know anything about this?

Crash on Windows

Traceback (most recent call last):
  File "C:\Program Files\Python\Scripts\qr-filetransfer-script.py", line 33, in <module>
    sys.exit(load_entry_point('qr-filetransfer==2.7', 'console_scripts', 'qr-filetransfer')())
  File "C:\Program Files\Python\lib\site-packages\qr_filetransfer\qr_filetransfer.py", line 527, in main
    start_download_server(file_path=args.file_path, debug=args.debug, custom_port=args.port, ip_addr=args.ip_addr, auth=args.auth)
  File "C:\Program Files\Python\lib\site-packages\qr_filetransfer\qr_filetransfer.py", line 369, in start_download_server
    SSID = get_ssid()
  File "C:\Program Files\Python\lib\site-packages\qr_filetransfer\qr_filetransfer.py", line 299, in get_ssid
    interface_info = os.popen("netsh.exe wlan show interfaces").read()
  File "C:\Program Files\Python\lib\encodings\cp1251.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 526: character maps to <undefined>

This is probably caused by incorrect encoding of the response from os.popen("netsh.exe wlan show interfaces") (Russian language)

How fix it: https://stackoverflow.com/a/47781109/15301038

Allow zipping files and encrypt them with a password

Should we add and option where users can use a flag like this, -zip to zip the file even though it is not a directory/folder? We could also add an option where when the user is zipping, they have an option to encrypt it with a password.

# Zipping the file before uploading
$ python3 qr-filetransfer.py -zip /path/to/file
# Zipping and encrypting it with a password before uploading
$ python3 qr-filetransfer.py -ezip /path/to/file

The zipping part might be easy to add but adding the password protection will need some work.
I read that the zipfile and the shutil module does not have an option to zip the file with a password. So the only method I can think of is to use subprocess and execute a bash command;

$ zip -e ZipFile.zip file.txt
Enter password:
Verify password:

So, we can use subprocess or we can just not have the password protection idea and just add the feature to zip the file if the user wants too even though its not a directory.

What are your guys thoughts?

Cannot open file that start with '~'

cat test.py

file = open('~/123', 'wb')

result:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    file = open('~/123', 'wb')
FileNotFoundError: [Errno 2] No such file or directory: '~/123'

Regression from commit b37a692

Files disappearing

Currently the user's files disappear and then get deleted, so I've created a pull request to address that here: #3 ๐Ÿ˜„

ConnectionResetError: [Errno 104] Connection reset by peer

OS: Ubuntu 18.04 LTS (Desktop), 64-bit

Error occured with both pip3 and Github install. QR code was generated, but threw this when I tried to download via phone.

192.168.8.137 - - [06/May/2019 20:29:40] "GET /Training-Form.docx HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('192.168.8.137', 46964)
Traceback (most recent call last):
  File "/usr/lib/python3.6/socketserver.py", line 317, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 348, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.6/socketserver.py", line 721, in __init__
    self.handle()
  File "/usr/lib/python3.6/http/server.py", line 418, in handle
    self.handle_one_request()
  File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
    method()
  File "./qr-filetransfer", line 57, in do_GET
    super().do_GET()
  File "/usr/lib/python3.6/http/server.py", line 639, in do_GET
    self.copyfile(f, self.wfile)
  File "/usr/lib/python3.6/http/server.py", line 800, in copyfile
    shutil.copyfileobj(source, outputfile)
  File "/usr/lib/python3.6/shutil.py", line 82, in copyfileobj
    fdst.write(buf)
  File "/usr/lib/python3.6/socketserver.py", line 800, in write
    self._sock.sendall(b)
ConnectionResetError: [Errno 104] Connection reset by peer
----------------------------------------

Dependency install

Environment: Linux bloop 5.0.12-arch2-1-ARCH #1 SMP PREEMPT Sat May 4 21:09:16 UTC 2019 x86_64 GNU/Linux

Installed this tool, upon running it, faced an error that says "iwgetid" not found.
I think this is used to fetch the wifi name.
is it possible to use any other tool to fetch the name of the network.

Thanks.

When transferring a video a broken pipe error occurs.

Error Log for your connivence:

Exception happened during processing of request from ('192.168.113.25', 49767)
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 646, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 720, in __init__
    self.handle()
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 426, in handle
    self.handle_one_request()
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 414, in handle_one_request
    method()
  File "/usr/local/bin/qr-filetransfer", line 37, in do_GET
    super().do_GET()
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 653, in do_GET
    self.copyfile(f, self.wfile)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/server.py", line 844, in copyfile
    shutil.copyfileobj(source, outputfile)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py", line 82, in copyfileobj
    fdst.write(buf)
  File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 799, in write
    self._sock.sendall(b)
BrokenPipeError: [Errno 32] Broken pipe

Was using an MP4 which was downloaded from Youtube as an mkv and then converted using ffmepg.
Maybe a weird issue, have been able to replicate it however. Hope this helps ๐Ÿ‘

Show SSID on Windows

It would be nice if Windows users could have their SSID shown when qr-filetransfer runs.
At the moment the SSID only shows on MacOS and Linux.

I dont know how to get the SSID on Windows because I dont use Windows. If someone is willing to help and test it, that would be really appreciated.

usage issue

I'm getting this message while transferring - "Make sure that your smartphone is connected to None"

Also, the scanner (default Xiaomi F1) can't scan the QR provided via the terminal. I've tried that in git-bash, cmder, and basic command line.

Tried the following
qr-filetransfer.py /c/Users/RIFAT/Desktop/test.jpg

Error when running it on MacOS

When I run it, I get this error:

Traceback (most recent call last):
  File "/usr/local/bin/qr-filetransfer", line 142, in <module>
    main()
  File "/usr/local/bin/qr-filetransfer", line 139, in main
    start_server(fname=sys.argv[1], cwd=CURRENT_DIR)
  File "/usr/local/bin/qr-filetransfer", line 38, in start_server
    SSID = get_ssid()
  File "/usr/local/bin/qr-filetransfer", line 17, in get_ssid
    proc = Popen(["iwgetid", "-r"], stdout=PIPE)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 769, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1516, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'iwgetid': 'iwgetid'

Why this error?
Well iwgetid is Linux command wont work on MacOS. This command is used to fetch the SSID. This also has to be fixed for Windows

I will fix this as soon as possible.

Allows other files to be downloaded too

Can you update the code so only the file passed via the command line parameter is shared? For example, if you are in the directory where you cloned this repository and issue "./qr-filetransfer requirements.txt" and get a QR code that resolves to http://192.168.1.100:4415/requirements.txt and you modify that URL to replace "requirements.txt" with "screenshot.png", it'll serve up that screenshot too. Worse yet, if you remove the filename from the URL, you end up with a browseable view of the directory you shared the file from: http://192.168.1.100:4415 leads to:
Directory listing for /
.git/
qr-filetransfer.py
README.md
requirements.txt
screenshot.png

I realize this is supposed to be a quick and easy tool that's left running only for the duration of a quick file transfer, but it would be nice to actually only be serving up one file when the purpose of this utility is to serve up one file.

A logo for qr-filetransfer

Making a logo for qr-filetransfer would be really cool.
Not sure how the logo should look like but maybe having a terminal icon combined with a qrcode would be cool.

The terminal icon below is nice
terminal-icon

Script wont work

I have gone through the code and I figured out that the script will not work because:

  • You are starting the server at the temporary directory, but encoding the qr code with url to path I passed while executing the script.
    os.chdir(TEMP_DIR_NAME)

    handler = http.server.SimpleHTTPRequestHandler
    httpd = socketserver.TCPServer(("", PORT), handler)
    # This is the url to be encoded into the QR code
    address = "http://" + str(LOCAL_IP) + ":" + str(PORT) + "/" + fname
  • One more thing what if the file have spaces in the filename.
    • Solution : Which i can propose is to parse the file name replace "spaces" with "%20"

Authenthication option

Would be very cool if users could have a flag where they could pass a password and username so that when they scan the QR code and visit the url, they will be prompted with a username and password.

This would be very useful for people who would like extra security.

They could pass the credentials like this:
username:password

Here is an example on how the code would look like.
https://gist.github.com/fxsjy/5465353


@npes87184 Do you want to take this task? You are very good with the socketserver and http.server modules.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.