transfer.sh
transfer.sh copied to clipboard
Zsh/Bash function: Be compatible with BSD's, macOS' and Linux' `du` command and add more examples
Relates to #475, #478 and #483.
This improves the function transfer()
to be able to upload files with spaces in their filenames.
Every space character
is replaced with the URL encoding character
: %20
.
I also added some more examples.
$ transfer --help
[...]
EXAMPLES:
[...]
Upload multiple files with spaces in their filename from the current working directory:
transfer "image 1.img" image\ 2.img
[...]
Upload multiple files from a different directory:
transfer transfer /tmp/{image1.img,image\ 1.img,"image 2.img"}
[...]
$ transfer "image 1.img" image\ 2.img
4K image 1.img
4K image 2.img
8K total
Do you really want to upload the above files (2) to "transfer.sh"? (Y/n):
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/V4X6y0/image%201.img/gBjLz3jMRxd4"
Delete token: gBjLz3jMRxd4
Download link: https://transfer.sh/V4X6y0/image%201.img
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/CHLy0j/image%202.img/hPd1EfqSbCk7"
Delete token: hPd1EfqSbCk7
Download link: https://transfer.sh/CHLy0j/image%202.img
image 1.img |
image 2.img |
---|---|
![]() |
![]() |
@keks24 thanks, but indeed it seems to me that this was already fixed by https://github.com/dutchcoders/transfer.sh/commit/343427d3b927d0426b22d34c8921cde5a8221844
can you test and in case just add the extra examples? (with a proper commit list ;))
I also realised that https://github.com/dutchcoders/transfer.sh/blob/main/README.md?plain=1#L297 is not BSD compatible
it should be something like du -c --si -H "${file_array[@]}" >&2
can you test and in case just add the extra examples? (with a proper commit list ;))
Sure!
It seems, that resetting and force-pushing my branch closed this pull request.
I also realised that https://github.com/dutchcoders/transfer.sh/blob/main/README.md?plain=1#L297 is not BSD compatible it should be something like
du -c --si -H "${file_array[@]}" >&2
I will figure something out and open this pull request again, when I am done testing. :)
It should work for almost any character in the filename now. There are still issues with curly braces, but who uses them in filenames anyways?:
$ transfer \\ff\{fff\}
4K \ff{fff}
4K total
Do you really want to upload the above files (1) to "transfer.sh"? (Y/n):
curl: Can't open '\fffff'!
curl: try 'curl --help' or 'curl --manual' for more information
curl: (26) Failed to open/read local data from file/application
Download link:
$ transfer "{fff}"
4K {fff}
4K total
Do you really want to upload the above files (1) to "transfer.sh"? (Y/n):
curl: Can't open 'fff'!
curl: try 'curl --help' or 'curl --manual' for more information
curl: (26) Failed to open/read local data from file/application
Download link:
$ transfer '{fff}'
4K {fff}
4K total
Do you really want to upload the above files (1) to "transfer.sh"? (Y/n):
curl: Can't open 'fff'!
curl: try 'curl --help' or 'curl --manual' for more information
curl: (26) Failed to open/read local data from file/application
Download link:
$ transfer '\{fff\}'
'\{fff\}' could not be found or is not a file.
$ transfer ssdjfl\{
4K ssdjfl{
4K total
Do you really want to upload the above files (1) to "transfer.sh"? (Y/n):
curl: (3) unmatched brace in URL position 7:
ssdjfl{
^
Download link:
Other special characters do work:
$ tree -FC
./
├── \!"§$%&\(\)=?*+_-:;,\>\<\>\| ²³¼½¬[]¸
├── ff\=\?43758&§
├── image 2.img
├── image 2.imgffff -> nom/image 2.imgffff
└── nom/
└── image 2.imgffff
1 directory, 5 files
$ transfer ff\\=\\\?43758\&§ \\\!\"§\$%\&\\\(\\\)=\?\*+_-:\;,\\\>\\\<\\\>\\\|\ ²³¼½¬\[\]¸ image\ 2.img image\ 2.imgffff
4K ff\=\?43758&§
4K \!"§$%&\(\)=?*+_-:;,\>\<\>\| ²³¼½¬[]¸
4K image 2.img
4K image 2.imgffff
16K total
Do you really want to upload the above files (4) to "transfer.sh"? (Y/n):
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/7NcqAc/%3F43758&%C2%A7/fTuWzJh7DU7M"
Delete token: fTuWzJh7DU7M
Download link: https://transfer.sh/7NcqAc/%3F43758&%C2%A7
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/cIvfV5/%7C%20%C2%B2%C2%B3%C2%BC%C2%BD%C2%AC%5B%5D%C2%B8/VXCvWWmeob1s"
Delete token: VXCvWWmeob1s
Download link: https://transfer.sh/cIvfV5/%7C%20%C2%B2%C2%B3%C2%BC%C2%BD%C2%AC%5B%5D%C2%B8
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/Q9t7aI/image%202.img/0LDqHW2LLx0r"
Delete token: 0LDqHW2LLx0r
Download link: https://transfer.sh/Q9t7aI/image%202.img
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/jkMlbg/image%202.imgffff/s30Xod3kHGeb"
Delete token: s30Xod3kHGeb
Download link: https://transfer.sh/jkMlbg/image%202.imgffff
@aspacca, please have a look. :)
Other special characters do work:
it seems that filename parsing does not match 1:1 the original filename in some cases: see https://transfer.sh/7NcqAc/%3F43758&%C2%A7 and https://transfer.sh/cIvfV5/%7C%20%C2%B2%C2%B3%C2%BC%C2%BD%C2%AC%5B%5D%C2%B8
I wonder if it's curl not sending the proper value
Other special characters do work:
it seems that filename parsing does not match 1:1 the original filename in some cases: see https://transfer.sh/7NcqAc/%3F43758&%C2%A7 and https://transfer.sh/cIvfV5/%7C%20%C2%B2%C2%B3%C2%BC%C2%BD%C2%AC%5B%5D%C2%B8
I wonder if it's curl not sending the proper value
This may be solved by using either of the parameters of curl
, which are POST
requests:
--data-binary
--data-raw
--data-urlencode
--data
But these are mutually exclusive to --form
, --head
and --upload-file
. The latter is used in the function.
I will have a deeper look on this later on.
@keks24 any update on this?
@aspacca, I still have it on my to do list. There are still some test files, which I want to upload.
I will come back to it, when I have time. :)
@aspacca, I have tested uploading my test files:
$ ls -l
total 12
-rw-r--r-- 1 ramon ramon 5 Sep 19 2022 'ff\=\?43758&§'
-rw-r--r-- 1 ramon ramon 5 Sep 19 2022 'ff\=\@(=§%uittj'
-rw-r--r-- 1 ramon ramon 5 Sep 19 2022 '\!"§$%&\(\)=?*+_-:;,\>\<\>\| ²³¼½¬[]¸'
$ transfer *
4K \!"§$%&\(\)=?*+_-:;,\>\<\>\| ²³¼½¬[]¸
4K ff\=\?43758&§
4K ff\=\@(=§%uittj
12K total
Do you really want to upload the above files (3) to "transfer.sh"? (y/N): y
######################################################################################################################################################################################################################################## 100.0%
Download link: </html>
######################################################################################################################################################################################################################################## 100.0%
Delete command: curl --request DELETE "https://transfer.sh/n33gH7/ff%5C=%5C/bG38pYQQiTVz"
Delete token: bG38pYQQiTVz
Download link: https://transfer.sh/n33gH7/ff%5C=%5C
######################################################################################################################################################################################################################################## 100.0%
Download link: </html>
The first and third file are uploaded and do not return any useful results.
The second file is still uploaded as f\=\
, but I think, that these are neglectable edge cases. :)