Пример #1
0
 def __init__(self,
              loop,
              host='localhost',
              port=2221,
              user=None,
              password=None):
     if user:
         users = aioftp.User(user, password),
         self.server = aioftp.Server(users, loop=loop)
     else:
         # Setup server with anonymous login
         self.server = aioftp.Server(loop=loop)
     self.host = host
     self.port = port
Пример #2
0
def test_user_manager_timeout():

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(None)

    server = aioftp.Server(
        SlowUserManager(None, timeout=1, loop=loop),
        loop=loop)
    client = aioftp.Client(loop=loop)

    @asyncio.coroutine
    def coro():

        try:

            yield from server.start(None, 8888)
            yield from client.connect("127.0.0.1", 8888)
            yield from client.login()

        finally:

            server.close()
            yield from server.wait_closed()

    loop.run_until_complete(coro())
Пример #3
0
            def run_in_loop(s_args, s_kwargs, c_args, c_kwargs):

                logging.basicConfig(
                    level=logging.INFO,
                    format="%(asctime)s [%(name)s] %(message)s",
                    datefmt="[%H:%M:%S]:",
                )

                loop = asyncio.new_event_loop()
                asyncio.set_event_loop(None)

                server = aioftp.Server(*s_args, loop=loop, **s_kwargs)
                client = aioftp.Client(*c_args, loop=loop, **c_kwargs)

                try:

                    loop.run_until_complete(f(loop, client, server))

                finally:

                    if hasattr(server, "server"):

                        server.close()
                        loop.run_until_complete(server.wait_closed())

                    if hasattr(client, "writer"):

                        client.close()

                    loop.close()
Пример #4
0
            def run_in_loop(s_args, s_kwargs, c_args, c_kwargs):

                loop = asyncio.new_event_loop()
                asyncio.set_event_loop(None)

                server = aioftp.Server(*s_args, loop=loop, **s_kwargs)
                client = aioftp.Client(*c_args, loop=loop, **c_kwargs)

                coro = asyncio.coroutine(f)
                try:

                    loop.run_until_complete(coro(loop, client, server))

                finally:

                    if hasattr(server, "server"):

                        server.close()
                        loop.run_until_complete(server.wait_closed())

                    if hasattr(client, "writer"):

                        client.close()

                    loop.close()
Пример #5
0
args = parser.parse_args()
print("aioftp v{}".format(aioftp.__version__))

if not args.quiet:
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s [%(name)s] %(message)s",
        datefmt="[%H:%M:%S]:",
    )
if args.memory:
    user = aioftp.User(args.login, args.password, base_path="/")
    path_io_factory = aioftp.MemoryPathIO
else:
    if args.home:
        user = aioftp.User(args.login, args.password, base_path=args.home)
    else:
        user = aioftp.User(args.login, args.password)
    path_io_factory = aioftp.PathIO

server = aioftp.Server([user], path_io_factory=path_io_factory)

loop = asyncio.get_event_loop()
loop.run_until_complete(server.start(args.host, args.port))
try:
    loop.run_forever()
except KeyboardInterrupt:
    server.close()
    loop.run_until_complete(server.wait_closed())
    loop.close()
Пример #6
0
import docopt

import aioftp

args = docopt.docopt(__doc__, version=aioftp.__version__)
print(str.format("aioftp v{}", aioftp.__version__))

if not args["--quiet"]:

    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s %(message)s",
        datefmt="[%H:%M:%S]:",
    )

user = aioftp.User(args["<login>"], args["<password>"])
server = aioftp.Server([user])

loop = asyncio.get_event_loop()
loop.run_until_complete(server.start(args["--host"], int(args["--port"])))
try:

    loop.run_forever()

except KeyboardInterrupt:

    server.close()
    loop.run_until_complete(server.wait_closed())
    loop.close()
Пример #7
0
        datefmt="[%H:%M:%S]:",
    )

if not args["--async"]:
    ftp = threaded_server.FTPserver(engine, args["--host"],
                                    int(args["--port"]))
    ftp.daemon = True
    ftp.start()
    print('On', args["--host"], ':', args["--port"])
    input('Enter to end...\n')
    ftp.stop()

else:
    user = aio_helpers.GameUser(engine=engine,
                                login="******",
                                base_path=pathlib.PurePosixPath("/"))
    OurGamePathIO = functools.partial(aio_helpers.GamePathIO, root=engine)
    server = aioftp.Server([user], path_io_factory=OurGamePathIO)

    loop = asyncio.get_event_loop()
    loop.run_until_complete(server.start(args["--host"], int(args["--port"])))
    try:

        loop.run_forever()

    except KeyboardInterrupt:

        server.close()
        loop.run_until_complete(server.wait_closed())
        loop.close()
Пример #8
0
async def main():
    server = aioftp.Server([user], path_io_factory=path_io_factory)
    await server.run(args.host, args.port, family=family)