It's been many years, but lastdir - "/" or lastdir - "" don't make sense, so it should be (lastdir - path) ? "/" : ""
Please also use the -v command line flag to get debug output from libcurl.
Do not create empty attributes for tags.