diff --git a/sys/shell/commands/sc_nanocoap_vfs.c b/sys/shell/commands/sc_nanocoap_vfs.c index e78688a7e597..fa2797254cd6 100644 --- a/sys/shell/commands/sc_nanocoap_vfs.c +++ b/sys/shell/commands/sc_nanocoap_vfs.c @@ -96,3 +96,35 @@ int _nanocoap_get_handler(int argc, char **argv) } return res; } + +int _nanocoap_put_handler(int argc, char **argv) +{ + int res; + char buffer[64]; + char *file, *url; + + if (argc < 3) { + printf("Usage: %s \n", argv[0]); + return -EINVAL; + } + + file = argv[1]; + url = argv[2]; + + if (_is_dir(url)) { + const char *basename = strrchr(file, '/'); + if (basename == NULL) { + return -EINVAL; + } + snprintf(buffer, sizeof(buffer), "%s%s", url, basename + 1); + url = buffer; + } + + res = nanocoap_vfs_put(url, file); + if (res < 0) { + printf("Upload failed: %s\n", strerror(-res)); + } else { + printf("Saved to %s\n", url); + } + return res; +} diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index fbad2b153abf..ba76c33f5c86 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -189,6 +189,7 @@ extern int _loramac_handler(int argc, char **argv); #ifdef MODULE_NANOCOAP_VFS extern int _nanocoap_get_handler(int argc, char **argv); +extern int _nanocoap_put_handler(int argc, char **argv); #endif #ifdef MODULE_NICE @@ -274,6 +275,7 @@ const shell_command_t _shell_command_list[] = { #endif #ifdef MODULE_NANOCOAP_VFS {"nget", "download a file from a CoAP server", _nanocoap_get_handler}, + {"nput", "upload a file to a CoAP server", _nanocoap_put_handler}, #endif #ifdef MODULE_GNRC_IPV6_NIB {"nib", "Configure neighbor information base", _gnrc_ipv6_nib},