def port_fail(username, password): client = Client(SERVER_ADDR, username, password) try: client.connect(SERVER_ADDR) login(client) addr = client.get_free_port() request = 'PORT %s,%s\r\n' % addr client.send_request(request) resp = client.get_response(request) assert resp == '501 Syntax error in parameters or arguments' finally: client.clear()
def exec_cwd(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) target_pwd = 'server_fs/%s' % username request = 'CWD %s\r\n' % target_pwd client.send_request(request) resp = client.get_response(request) assert '250 Requested file action okay, completed.' == resp finally: client.clear()
def mode_fail(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) assert client.mode == 'S' req = 'MODE ABCDEF\r\n' target = '501 Syntax error in parameters or arguments' client.send_request(req) resp = client.get_response(req) assert resp == target assert client.mode == 'S' finally: client.clear()
def mode(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) assert client.mode == 'S' req = 'MODE %s-%s\r\n' % ('B', 'Block') target = '200 Command okay' client.send_request(req) resp = client.get_response(req) assert resp == target assert client.mode == 'B' finally: client.clear()
def mkd_fail(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) dirname = username request = 'MKD %s\r\n' % dirname client.send_request(request) resp = client.get_response(request) dir_path = 'server_fs/%s' % dirname assert os.path.isdir(dir_path) assert '550 Requested action not taken.File unavailable' == resp finally: client.clear()
def mkd(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) dirname = username request = 'MKD %s\r\n' % dirname client.send_request(request) resp = client.get_response(request) dir_path = 'server_fs/%s' % dirname assert os.path.isdir(dir_path) assert '257 "%s" created' % dir_path == resp finally: client.clear()
def exec_pasv(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) addr = client.get_free_port() client.make_data_connect(addr) request = 'PORT %s,%s\r\n' % addr client.send_request(request) client.get_response(request) request = 'PASV\r\n' client.send_request(request) resp = client.get_response(request) pattern = '(?P<response>.*) (?P<addr>(\d|.)*),(?P<port>\d+)' rs = re.match(pattern, resp) resp = rs.group('response') addr = rs.group('addr'), int(rs.group('port')) assert '227 Entering Passive Mode.' == resp client.make_data_connect(addr, True) client.data_sock.getpeername() == addr finally: client.clear()
def port(username, password): client = Client(SERVER_ADDR, username, password) try: client.connect(SERVER_ADDR) login(client) addr = client.get_free_port() client.make_data_connect(addr) request = 'PORT %s,%s\r\n' % addr client.send_request(request) resp = client.get_response(request) assert resp == '200 Command okay' assert client.data_sock.fileno() != -1 addr = client.get_free_port() client.make_data_connect(addr) request = 'PORT %s,%s\r\n' % addr client.send_request(request) resp = client.get_response(request) assert resp == '200 Command okay' assert client.data_sock.fileno() != -1 finally: client.clear()
def login(self, username, password): client = Client(SERVER_ADDR, username, password)
def exec_cdup(username, password): client = Client(SERVER_ADDR, username, password) client.connect(SERVER_ADDR) try: login(client) pwd = 'server_fs/%s' % client.name client.send_CWD(pwd) request = 'CDUP\r\n' client.send_request(request) resp = client.get_response(request) assert '250 Requested file action okay, completed.' == resp finally: client.clear()