Skip to content

Password as CLI argument #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# empty file
__pycache__/
*.py[cod]
30 changes: 19 additions & 11 deletions webrepl_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def help(rc=0):
exename = sys.argv[0].rsplit("/", 1)[-1]
print("%s - Perform remote file operations using MicroPython WebREPL protocol" % exename)
print("Arguments:")
print(" <host>:<remote_file> <local_file> - Copy remote file to local file")
print(" <local_file> <host>:<remote_file> - Copy local file to remote file")
print(" [-p password] <host>:<remote_file> <local_file> - Copy remote file to local file")
print(" [-p password] <local_file> <host>:<remote_file> - Copy local file to remote file")
print("Examples:")
print(" %s script.py 192.168.4.1:/another_name.py" % exename)
print(" %s script.py 192.168.4.1:/app/" % exename)
print(" %s 192.168.4.1:/app/script.py ." % exename)
print(" %s -p hackme123 192.168.4.1:/app/script.py ." % exename)
sys.exit(rc)

def error(msg):
Expand All @@ -191,10 +191,20 @@ def parse_remote(remote):


def main():

if len(sys.argv) != 3:
if len(sys.argv) not in [3, 5]:
help(1)

passwd = None
for i in range(len(sys.argv)):
if sys.argv[i] == '-p':
sys.argv.pop(i)
passwd = sys.argv.pop(i)
break

if not passwd:
import getpass
passwd = getpass.getpass()

if ":" in sys.argv[1] and ":" in sys.argv[2]:
error("Operations on 2 remote files are not supported")
if ":" not in sys.argv[1] and ":" not in sys.argv[2]:
Expand All @@ -207,17 +217,17 @@ def main():
if os.path.isdir(dst_file):
basename = src_file.rsplit("/", 1)[-1]
dst_file += "/" + basename
print("%s %s from %s:%d and save as %s" %
(op, src_file, host, port, os.path.abspath(dst_file)))
else:
op = "put"
host, port, dst_file = parse_remote(sys.argv[2])
src_file = sys.argv[1]
if dst_file[-1] == "/":
basename = src_file.rsplit("/", 1)[-1]
dst_file += basename

if 1:
print(op, host, port)
print(src_file, "->", dst_file)
print("%s %s to %s:%d and save as %s" %
(op, os.path.abspath(src_file), host, port, dst_file))

s = socket.socket()

Expand All @@ -230,8 +240,6 @@ def main():

ws = websocket(s)

import getpass
passwd = getpass.getpass()
login(ws, passwd)
print("Remote WebREPL version:", get_ver(ws))

Expand Down