def main(): server = Server() commandNet = TestNetwork(server, False) dataNet = TestNetwork(server, True) host = "foo" client = Client(commandNet, dataNet) suc = client.connect(host, 21) print "C:Test connected:", suc client.login("anonymous", "*****@*****.**") files = client.listFiles() if files is not None: for i in files: print i.toString() else: print("C:No listing obtained.") f = client.retrieveFile("xx") if f is not None: print "C:File is:\r\n", f else: print "C:File transfer failed." print "C:Testing stream api..." stream = client.retrieveFileStream("xx") buf = "" print "C:reading from stream byte by byte" c = stream.read() while c != -1: buf += chr(c); c = stream.read() print "C:closing stream" stream.close(); print "C:File from stream:" print buf print "C: ask and close" stream = client.retrieveFileStream("xx2") stream.close(); print "C:Healthy?" f = client.retrieveFile("xx2") # suppress aggresive optimization print "C:", (file is not None) client.changeWorkingDirectory("a_dir") client.changeWorkingDirectory("b_dir") # suppress aggresive optimization client.deleteFile("a_file") client.deleteFile("b_file") #suppress aggresive optimization client.logout() print "C:TestDone."
def main(clientBug): server = Server() server.setExperimentErrorDataTransferConfirmation(True) commandNet = TestNetwork(server, False) dataNet = TestNetwork(server, True) host = "foo" client = Client(commandNet, dataNet) client.setDataTransferConfirmationBug(clientBug) client.setPasvResponseReadingBug(clientBug) suc = client.connect(host, 21) print "C:Test connected:", suc client.login("anonymous", "*****@*****.**") f = client.retrieveFile("xx") if f is not None: print "C:File is:\r\n", f else: print "C:File transfer failed." print "C:##Second shot..." f = client.retrieveFile("xx") if f is not None: print "C:File is(2):\r\n", f else: print "C:File transfer failed.(2)" print "C:##Third shot..." f = client.retrieveFile("xx") if f is not None: print "C:File is(3):\r\n", f else: print "C:File transfer failed.(3)" print "C:##Stream shot..." stream = client.retrieveFileStream("xx") counter = 0 while True: c = stream.read() if c == -1: stream.close() break else: counter += 1 print "Stream contained %d bytes" % counter client.logout() print "C:TestDone."
def main(): config = RandServerConfig() config.setSERVER_LEVEL(0) config.setREADLINE_LEVEL(2) server = RandServer(config) commandNet = TestNetwork(server, False, config) dataNet = TestNetwork(server, True) host = "foo" client = Client(commandNet, dataNet) client.setPasvResponseReadingBug(True) # This sets the artificial clien bug: #client.setDataTransferConfirmationBug(True) suc = client.connect(host, 21) print "C:Test connected:", suc if not suc: return suc = client.login("anonymous", "*****@*****.**") if not suc: return f = client.retrieveFile("xx") if f is None: pass else: print f f = client.retrieveFile("xx2") if f is None: pass else: print f stream = client.retrieveFileStream("xx") buf = "" if stream is not None: c = stream.read() while c != -1: buf += chr(c); c = stream.read() stream.close(); print buf suc = client.changeWorkingDirectory("b_dir") if not suc: pass suc = client.deleteFile("a_file") if not suc: pass suc = client.logout() if not suc: pass print "C:TestDone."
def main(): """ Tests various sequences of commands. """ server = Server() commandNet = TestNetwork(server, False) dataNet = TestNetwork(server, True) host = "foo" client = Client(commandNet, dataNet) suc = client.connect(host, 21) print "C:Test connected:", suc if not suc: return suc = client.login("anonymous", "*****@*****.**") if not suc: return for i in range(3): cmd = random(3) if cmd == 0: f = client.retrieveFile("xx") if f is None: pass else: print f elif cmd == 1: stream = client.retrieveFileStream("xx") buf = "" if stream is not None: c = stream.read() while c != -1: buf += chr(c) c = stream.read() stream.close() print buf elif cmd == 2: suc = client.changeWorkingDirectory("b_dir") if not suc: pass elif cmd == 3: files = client.listFiles() if files is None: pass suc = client.logout() if not suc: pass print "C:TestDone (random 2)."
def main(dataTransferConfirmationBug, pasvResponseReadingBug, cuttingServer): """ Mainly for counting states of JPF and for comparison with simulation """ assert not (dataTransferConfirmationBug and pasvResponseReadingBug) config = None if cuttingServer: config = RandServerConfig() config.setSERVER_LEVEL(0) config.setREADLINE_LEVEL(2) server = RandServer(config) commandNet = TestNetwork(server, False, config) dataNet = TestNetwork(server, True) host = "foo" client = Client(commandNet, dataNet) # This sets the artificial clien bug: client.setDataTransferConfirmationBug(dataTransferConfirmationBug) client.setPasvResponseReadingBug(pasvResponseReadingBug) suc = client.connect(host, 21) print "C:Test connected:", suc if not suc: return suc = client.login("anonymous", "*****@*****.**") if not suc: return f = client.retrieveFile("xx") if f is None: pass else: print f f = client.retrieveFile("xx2") if f is None: pass else: print f suc = client.logout() if not suc: pass print "C:TestDone."