Coders Packet

Google Drive type File Explorer Web application using python3 Flask and Jquery

By Narender Bhadu

This packet is web file explorer with google drive like User Interface. With built in video player and image viewer and a terminal to execute command on a remote host.

Remote file manager web app In Python3


1. file explorer

2. Terminal

3. Image and video viewer


library and frameworks used

1. flask

2. Jquery

3. Jhinjha 2

4. subprocess

Functions and usage

server can be started by simply running file with python3

from flask import Flask,send_file
import os

# this lib will reload custom functions after every change
# hence no need to restart server after every change
import importlib

# custom functions
import functions

# flask root object

# handles requests for index page
def index():
  return functions.index()

# when change directory (cd) is required
def change_page():
  return functions.change_page()

# to handle terminal commands
def execute_command():
  return functions.execute_command()

# to serve files other than index page
def requested_files(filename):
  # to edit any file in text editor
  if filename == "file.html":
    return functions.files()
  # favion icon
  elif filename == "favicon.ico":
    return "" # not required so just returning an empty string
  # terminal UI page
  elif filename == "terminal.html": 
    return functions.terminal_page()
  # other files from directory like png,mp4 etc
    return send_file(filename)

if __name__=="__main__":
  # uncomment only for development debbuging
  # app.config['DEBUG']=True

  # runs server @ localhost"",port=5000)

  #runs server at wlan network can be accesible with other devices

Module named functions contains helper functions

# return list of files and folder in directory
def serve_items():
  # python list of names
  # we will items in group of 5 to arrange in a row
  dir_items = [[]]
  for x in os.listdir():
    # y will store absolute path of item
    # ext will store ext of item
    ext = x.lower().split(".",1)[-1]
    # if group is filled start new group of five items
    if len(dir_items[-1])==5:
    # if item is directory
    if os.path.isdir(x):
    # if item is a image
    elif ext in ["png","jpg"]:
    # if item is a video
    elif ext in ["mp4","mkv","3gp"]:
    # other files

  return dir_items

def index():
  # return app.html page
  return render_template("explorer.html",title="file explorer",dir_items=serve_items())

def terminal_page():
  # return terminal UI page
  return render_template("terminal.html")

def change_page():
  # returns content of changed directory after cd
  cd = request.values.get("cd")
  return render_template("serve_items.html",dir_items=serve_items())

def files():
  # return file editor page
  return render_template("file.html")

def execute_command():
  # return result of command
  cmd = request.values.get("cmd")
  return getoutput(cmd).replace("\n","

Download Complete Code


No comments yet