Skip to content

Commit

Permalink
Pyserved 2.0.2 Color Update!
Browse files Browse the repository at this point in the history
  • Loading branch information
shaurya-blip committed Jan 20, 2022
1 parent a289d33 commit 96de74a
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv
__pycache__
.DS_Store
2 changes: 1 addition & 1 deletion pyserved/LICENSE.txt → LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Shaurya Pratap Singh
Copyright (c) 2021 SblipDev.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PyServed v2.0.1
Made with love by Shaurya Pratap Singh
# PyServed v2.0.2
A beautiful cli made with python which can send files with blazing speed.

![pyserved in show](images/example.png)
## Installation

Using pip(for stable releases.) ->
Expand All @@ -18,23 +19,37 @@ $ python3 setup.py install

## Usage

Once installed, you can send files across computers.
Once installed, you will be able to send files across computers with the package and python on it.
If there is any problem you can file and issue on this repo.

To send files.
It will ask the file path.
### To listen for files

To send files, you will have to run the following command (The correct output is also shown):

```
$ sndfile
$ pdlisten
[SERVER]: Server is listening on 192.168.1.5:8080
[SERVER]: Waiting for a connection for files...
```

To get files.
To change the default port(8080), add the '-port XXXX' argument to the command and try again.
If someone else conects using the pyserved 'pdsnd' command. It will write the file to the current working directory

### To get files.

To send files, you will have to run the `pdsnd` command. It will prompt for the filepath of the file you want to send.
If everything goes right, the file will be sent to the person listening in the same network.
To change the default port(8080), add the '-port XXXX' argument to the command and try again.

```
$ getfile
```
$ pdsnd
Thats it.
Feel free to contribute.
Have a nice day
[SERVER] : Program Initialized at current directory './'
[SERVER] : Filename:
```


## Thats it.
Feel free to contribute to the package. I personally would really appreciate it.
Have a nice day
File renamed without changes.
File renamed without changes.
Binary file added images/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions pyserved/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
MAJOR UPDATE
2.0 -> Bought back cli and added support for ALL codec files.
2.0.1 -> Fixed bug with codecs.
2.0.2 -> Added colors! and error messages for when something goes wrong.
Shaurya Pratap Singh 2021
"""

__version__ = '2.0.1'
__version__ = '2.0.2'
__author__ = 'Shaurya Pratap Singh'
__message__ = 'Hail dogecoin! Hail hydra!'
__message__ = "Your time is limited, so don't waste it living someone else's life. Don't be trapped by dogma – which is living with the results of other people's thinking. -Steve Jobs"
40 changes: 28 additions & 12 deletions pyserved/client.py → pyserved/pdlisten.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
import readline
import os

HEADER = 64

from rich import print

HEADER = 64
class Client:
def __init__(self, server, port):
self.SERVER_HOST = server
self.SERVER_PORT = port
self.BUFFER_SIZE = 1024 * 100000
self.SEPARATOR = "<Order66>"
self.SEPARATOR = "<[(^_^)]>"
self.s = socket.socket()
self.s.bind((self.SERVER_HOST, self.SERVER_PORT))

Expand Down Expand Up @@ -78,6 +78,10 @@ def get_internal_ip():
PORT = 8080
ADDR = (SERVER, PORT)

def is_port_in_use() -> bool:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex((get_internal_ip(), PORT)) == 0

try:
if sys.argv[1] is None:
pass
Expand All @@ -90,19 +94,31 @@ def get_internal_ip():
except IndexError:
pass

if is_port_in_use() is True:
print("[bold red]Port 8080 is already in use in your network. Choose another port instead using the '-port' parameter.[/]")
exit()

try:
client = Client(SERVER, PORT)
print("[SERVER]: Server is running on {}:{}".format(SERVER, PORT))
print("[SERVER]: Waiting for a connection...")
print("[bold green][SERVER]:[/] Server is listening on {}:{}".format(SERVER, PORT))
print("[bold green][SERVER]:[/] Waiting for a connection for files...")
client.listen()
_, address = client.accept()
print("[SERVER] : Connection at {}:{}".format(address[0], address[1]))
print("[SERVER] : Waiting for a file...")
client.receive()
print("[SERVER] : Received file {}.".format(client.filename))
print("[bold green][SERVER]:[/] Connection from {}:{} accepted.".format(address[0], address[1]))
print("[bold green][SERVER]:[/] Reading file data.....")
try:
client.receive()
except ValueError:
print("\n[bold red]An error occured. Please try again in few seconds....[/]")
exit()
print("[bold green][SERVER]:[/] Received file '[bold yellow]{}[/]', saving to current directory.".format(client.filename))
client.write()
print("[SERVER]: File transferred successfully. Closing connection...")
print("[bold green][SERVER]:[/] File transferred successfully. Closing connection...")
client.close()
except KeyboardInterrupt:
print("\n[SERVER]: Keyboard interrupt.")
client.close()
print("\n[bold red]KeyboardInterrupt[/]")
exit()
except:
print("\n[bold red]Something went wrong. If the problem presists, contact the owner of the package at https://github.com/SblipDev/pyserved[/]")
exit()

31 changes: 18 additions & 13 deletions pyserved/server.py → pyserved/pdsnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
| |
| pyserved |
| |
| Only works with utf-8 |
| files. (for now.) |
| |
| By: |
| Shaurya Pratap Singh |
| 2021 © |
Expand All @@ -20,14 +17,16 @@


import socket
import tqdm
import os
import argparse
# import argparse
import readline
import sys

SEPARATOR = "<Order66>"
BUFFER_SIZE = 1024 * 100000 # 4KB
from rich import print
from rich.prompt import Prompt

SEPARATOR = "<[(^_^)]>"
BUFFER_SIZE = 1024 * 100000


def send_file(filename, host, port):
Expand Down Expand Up @@ -78,12 +77,18 @@ def get_internal_ip():
FORMAT = 'utf-8'

try:
print("[INFO] : Program Initialized at current directory.")
filename = input('[FILEPATH] : ')
print("[bold green][SERVER][/] : Program Initialized at current directory '{}'".format(SAVE_DIR))
filename = Prompt.ask("[bold green][SERVER][/] : Filename")
send_file(filename, SERVER, PORT)
print("[INFO] : Got file path successfully.")
print(f"[INFO] : Sending {filename} to {SERVER}:{PORT}")
print(f"[INFO] : Sent file. :)")
print("[bold green][SERVER][/] : Got file path successfully.")
print(f"[bold green][SERVER[/] : Sending [bold yellow]{filename}[/] to {SERVER}:{PORT}")
print(f"[bold green][SERVER][/] : Sent file. :)")
except KeyboardInterrupt:
print("\n[QUIT] : Keyboard Interrupt.")
print("\n[bold red]KeyboardInterrupt[/]")
exit()
except ConnectionRefusedError:
print(f"\n[bold red]Connection Refused. Please check the server program.[/]")
exit()
except FileNotFoundError:
print(f"\n[bold red]File '{filename}' does not exist. Please correct the file path and try again[/]")
exit()
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

setup(
name="pyserved",
version="2.0.1",
version="2.0.2",
description="Share files with your friends (on the same network though)",
long_description_content_type="text/markdown",
url="https://github.com/shaurya-blip/pyserved/",
url="https://github.com/SblipDev/pyserved/",
author="Shaurya Pratap Singh",
author_email="shaurya.p.singh21@gmail.com",
license="MIT",
packages=["pyserved"],
install_requires=['tqdm', 'netifaces'],
install_requires=['netifaces', 'rich'],
include_package_data=True,
scripts=['bin/getfile', 'bin/sndfile'],
scripts=['bin/pdlisten', 'bin/pdsnd'],
)
16 changes: 16 additions & 0 deletions testing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Pyserved module
1.1 -> Added support for all OS
1.2 -> Removed cli and just made a python package.
MAJOR UPDATE
2.0 -> Bought back cli and added support for ALL codec files.
2.0.1 -> Fixed bug with codecs.
Shaurya Pratap Singh 2021
"""

__version__ = '2.0.1'
__author__ = 'Shaurya Pratap Singh'
__message__ = 'Hail dogecoin! Hail hydra!'

0 comments on commit 96de74a

Please sign in to comment.