Code Monkey home page Code Monkey logo

yaftp's Introduction

yaftp: Yet another file transfer protocol

Weiwen Chen's fifth project of Computer Network course in FDU.

A simple ftp-like file transfer protocol package.

Simple ui: https://github.com/ofey404/yaftp-ui

Usage

Installation

git clone https://github.com/ofey404/yaftp.git
cd yaftp
pip install -e .

Then you can use yaftp package in python:

$ python
Python 3.9.1 (default, Dec  8 2020, 00:00:00) 
[GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaftp
>>> 

Set up a server

import yaftp

yaftp.YAFTPServer(
    address=("127.0.0.1", 2121),
    local_dir="tests/data",
    auth={
        "USER": "PASSWORD",
        "OFEY": "404",
        "ANONYMOUS": ""   # Blank means login without password
    }
).serve()

Interact with a server

import yaftp

c = yaftp.YAFTP(
    address=("127.0.0.1", 2121),
    user="USER",
    passwd="PASSWORD"
)

c.login()
# Out[2]: 230

c.dir()
# Out[3]: ['test_folder/', 'hello.txt']

c.get(name="hello.txt", savepath="saved_file")
# Out[4]: 213

%cat saved_file
# hello from the other side!

c.send(filepath="saved_file", name="hey.txt")
# Out[6]: 213

c.dir()
# Out[7]: ['test_folder/', 'hello.txt', 'hey.txt']

c.cd(path="test_folder")
# Out[8]: 212

c.dir()
# Out[9]: ['hey.txt']

c.quit()
# Out[10]: 231

Implementation detail

Super simple, just a toy, never care about performance.

Use async event loop to handle control connection, while firing other threads to deal with data connection.

Commands

  • LOGIN USER[:PASSWORD]
  • DIR [RELATIVE_PATH]
  • PWD
  • CD [RELATIVE_PATH]
  • GET FILENAME DATA_PORT
    • DATA_PORT should be opened in localhost before command is executed.
  • SEND FILENAME DATA_PORT
    • DATA_PORT: same as above.
  • DELETE FILENAME
  • BYE

Only support active mode

Implemented a ftp-like active mode, because it's easy, without much synchronizaion effort.

When sending or getting a file:

  • Client open a local data port, listening.
  • Client -- request --> Server
    • request specify the data port.
  • Server -- connect --> Client:data_port
    • then send file.

Vulnerabilities

I've try my best on error handling and prevent secure vulnerabilitys, like:

  • Prevent user dir or cd beyond root directory.

But I'm sure that's not enough, this library must be full of holes.

Reference

API Design refer to:

yaftp's People

Contributors

ofey404 avatar

Watchers

James Cloos avatar  avatar

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.