Socket
Socket
Sign inDemoInstall

github.com/lqr471814/websocket-ftp

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/lqr471814/websocket-ftp


Version published
Created
Source

websocket-ftp

A simple FTP protocol with client and server implemented in TypeScript and Golang.

Example (Client)

const buffer: Uint8Array = (new TextEncode()).encode("Testing Text")

new Transfer(
    "ws://example.server.com/filetransfer",
    [
        {
            Name: "Test File",
            Size: buffer.length,
            Type: "application/octet-stream",
            data: buffer
        },
    ],
    {
        onstart: () => {
            console.log("Transfer has started.")
        },
        onprogress: (r, t) => console.log(`Sent ${r} / ${t} bytes`),
        onsuccess: () =>
            console.log("Success!"),
        onclose: () =>
            console.log("Closed WS connection"),
    },
)

The client can also use a stream for the data attribute, this can be a nodeJS fs.ReadStream constructed from fs.createReadStream(path) or a the web ReadableStream from calling File.stream()

Keep in mind, you will need to wrap each with either the NodeFileStream or BrowserFileStream class.

Example (Server)

type Hooks struct{}

func (h Hooks) OnTransferRequest(t *Transfer) chan bool {
    log.Println("Got requests", t.Data.Files)
    c := make(chan bool, 1)
    c <- true
    return c
}

func (h Hooks) OnTransferUpdate(t *Transfer) {
    log.Println(
        "Progress",
        t.State.Received,
        "/",
        t.Data.Files[t.State.CurrentFile].Size,
    )
}

func (h Hooks) OnTransferComplete(t *Transfer, f File) {
    log.Println(f.Name, "has been received")
}

func (h Hooks) OnAllTransfersComplete(t *Transfer) {
    log.Println("Transfer", t.ID, "has completed")
}

server := NewServer(ServerConfig{
    Handlers: Hooks{},
})

server.Serve()

FAQs

Package last updated on 02 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc