Skip to content

Commit

Permalink
sys/shell: add 'nput' shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Apr 18, 2022
1 parent ec15496 commit 4129bbd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sys/shell/commands/sc_nanocoap_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file> <url>\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;
}
2 changes: 2 additions & 0 deletions sys/shell/commands/shell_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 4129bbd

Please sign in to comment.