Receive file: get
(self, arg, lpath="", r=True)
| 444 | |
| 445 | # ------------------------[ get <file> ]------------------------------ |
| 446 | def do_get(self, arg, lpath="", r=True): |
| 447 | "Receive file: get <file>" |
| 448 | if not arg: |
| 449 | arg = eval(input("Remote file: ")) |
| 450 | if not lpath: |
| 451 | lpath = self.basename(arg) |
| 452 | path = self.rpath(arg) if r else arg |
| 453 | str_recv = self.get(path) |
| 454 | if str_recv != c.NONEXISTENT: |
| 455 | rsize, data = str_recv |
| 456 | lsize = len(data) |
| 457 | # fix carriage return chars added by some devices |
| 458 | if lsize != rsize and len(conv().nstrip(data)) == rsize: |
| 459 | lsize, data = rsize, conv().nstrip(data) |
| 460 | # write to local file |
| 461 | file().write(lpath, data.encode()) |
| 462 | if lsize == rsize: |
| 463 | print((str(lsize) + " bytes received.")) |
| 464 | else: |
| 465 | self.size_mismatch(rsize, lsize) |
| 466 | |
| 467 | def size_mismatch(self, size1, size2): |
| 468 | size1, size2 = str(size1), str(size2) |