Use case:
I am trying to copy data/everything from my android mobile to laptop on same wifi, maintaining directory structure. I know there are tons of methods, but I love to do it this way (below) and need help. And then do whatever on the laptop with those files.
File samples/directory structure to upload from mobile to laptop ftp server –
dir1
|–1.mp3
|–dir2
|–download 1.jpg
|–download (2).jpg
How to reproduce:
In mobile I have terminal similar to Ubuntu. In laptop I am running ftp server using python.
From mobile I am running below command and it works fine, just that directory structure and dumping every file to the root directory of ftp (and I know why, recursive sub folder and files are not maintained bcz of the url call as it is not mentioning the path)
find dir1 -type f -exec curl -u ftp:ftp --ftp-create-dirs -T {} ftp://192.168.x.x/ ;
Point is, there is no filename/path in url of curl so there is no issue of url encoding. All files as it is uploaded to root directory.
So to maintain sub directory structure I have to do below url call.
find dir1 -type f -exec curl -u ftp:ftp --ftp-create-dirs -T {} ftp://192.168.x.x/{} ;
Now it will throw error for filenames having spaces or ( or ) or anything like that due to url encoding. For example for “download 1.jpg” and “download (2).jpg”
curl: (3) URL using bad/illegal format or missing URL
Stuffs I have tried so far (echo I have used below to show the variables values) –
find dir1 -type f -exec bash -c 'y=$(echo "$1"); fname=$(echo $y | sed "s/ /%20/g"); echo $y;echo $fname;echo ""; curl -u ftp:ftp --ftp-create-dirs -T $y ftp://192.168.x.x/$fname' bash {} ;
Output –
`dir1/1.mp3
dir1/1.mp3
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0
dir1/dir2/download 1.jpg
dir1/dir2/download%201.jpg
curl: Can’t open ‘dir1/dir2/download’
curl: try ‘curl –help’ for more information
curl: (26) Failed to open/read local data from file/application
dir1/dir2/download (2).jpg
dir1/dir2/download%20(2).jpg
curl: (3) URL using bad/illegal format or missing URL`
“—————————————–“
So you can see the problem I am having is with url encoding. Even I have done encoding for space it is not working. And there will be much more random characters.
I thought to use –data-urlencoding of curl but that won’t allow -G with -T, or -T with –data.
Plus there will be a “?” string added this way if it was going to work which is not my use case.