diff --git a/mavros/scripts/mavftp b/mavros/scripts/mavftp index ae20bc170..d541971b3 100755 --- a/mavros/scripts/mavftp +++ b/mavros/scripts/mavftp @@ -26,13 +26,6 @@ from mavros.utils import * from mavros.ftp import * -def check_ret(operation, ret): - if not ret.success: - fault(operation, "failed:", os.strerror(ret.r_errno)) - -# -*- subcommand handlers -*- - - def do_list(args): rospy.init_node("mavftp", anonymous=True) @@ -79,7 +72,18 @@ def do_rmdir(args): def do_upload(args): - raise NotImplementedError + rospy.init_node("mavftp", anonymous=True) + + mode = 'cw' if args.no_overwrite else 'w' + + with args.file as from_fd: + with FTPFile(args.path, mode) as to_fd: + while True: + buf = from_fd.read(1024) + if len(buf) == 0: + break; + + to_fd.write(buf) def main(): @@ -113,6 +117,7 @@ def main(): upload_args.set_defaults(func=do_upload) upload_args.add_argument('file', type=argparse.FileType('rb'), help="file to send") upload_args.add_argument('path', type=str, help="save path") + upload_args.add_argument('-n', '--no-overwrite', action="store_true", help="do not overwrite existing file") reset_args = subarg.add_parser('reset', help="reset") reset_args.set_defaults(func=do_reset) diff --git a/mavros/src/mavros/ftp.py b/mavros/src/mavros/ftp.py index 128d392d3..5b9224bc9 100644 --- a/mavros/src/mavros/ftp.py +++ b/mavros/src/mavros/ftp.py @@ -163,7 +163,6 @@ def ftp_unlink(path, ns="/mavros"): raise IOError(str(ex)) _check_raise_errno(ret) - return ret.list def ftp_mkdir(path, ns="/mavros"): @@ -202,7 +201,7 @@ def ftp_rename(old_path, new_path, ns="/mavros"): def ftp_checksum(path, ns="/mavros"): """Calculate CRC32 for :path:""" try: - checksum_cl = rospy.ServiceProxy(ns + "/ftp/rename", FileChecksum) + checksum_cl = rospy.ServiceProxy(ns + "/ftp/checksum", FileChecksum) ret = checksum_cl(file_path=path) except rospy.ServiceException as ex: raise IOError(str(ex))