Skip to content

Rate limiting SFTP operations #420

Answered by ronf
anthonyjmartinez asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a more complete example of what I was thinking:

import asyncio
import asyncssh

async def example(path: str, rate: float, block_size = 1024):
    loop = asyncio.get_event_loop()

    async with asyncssh.connect('localhost') as conn:
        async with conn.start_sftp_client() as sftp:
            async with sftp.open(path, "rb") as f:
                length = (await f.stat()).size
                pos = 0
                buffer = []
                start = last = loop.time()

                while pos < length:
                    data = await f.read(block_size)
                    if not data:
                        break

                    buffer.append(data)
                    

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@anthonyjmartinez
Comment options

Comment options

You must be logged in to vote
1 reply
@anthonyjmartinez
Comment options

Answer selected by anthonyjmartinez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants