Autocomplete filename #312

Closed
opened 2026-01-19 18:29:51 +00:00 by michael · 2 comments
Owner

Originally created by @cyberboysumanjay on GitHub.

I have a file who extension can vary every time. But I know the starting name.
For example, I have a file known as testvideo.mkv but it can be testvideo.mp4 also in the second run. I want the script to upload the file starting from testvideo.
I'm calling this command from terminal
curl --upload-file ./testvideo* https://transfer.sh
But when I call this from subprocess so that I can use this in a python script. It doesn't seem to work
curl: try 'curl --help' or 'curl --manual' for more information Traceback (most recent call last): File "test.py", line 16, in <module> upload_file('testvideo.mkv') File "test.py", line 11, in upload_file url = subprocess.check_output(cmd,shell=True) File "/usr/lib/python3.5/subprocess.py", line 626, in check_output **kwargs).stdout File "/usr/lib/python3.5/subprocess.py", line 708, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['curl', '--progress-bar', '--upload-file', './testvideo*', 'https://transfer.sh/']' returned non-zero exit status 2

Any help?
TIA

Originally created by @cyberboysumanjay on GitHub. I have a file who extension can vary every time. But I know the starting name. For example, I have a file known as testvideo.mkv but it can be testvideo.mp4 also in the second run. I want the script to upload the file starting from testvideo. I'm calling this command from terminal `curl --upload-file ./testvideo* https://transfer.sh` But when I call this from subprocess so that I can use this in a python script. It doesn't seem to work `curl: try 'curl --help' or 'curl --manual' for more information Traceback (most recent call last): File "test.py", line 16, in <module> upload_file('testvideo.mkv') File "test.py", line 11, in upload_file url = subprocess.check_output(cmd,shell=True) File "/usr/lib/python3.5/subprocess.py", line 626, in check_output **kwargs).stdout File "/usr/lib/python3.5/subprocess.py", line 708, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['curl', '--progress-bar', '--upload-file', './testvideo*', 'https://transfer.sh/']' returned non-zero exit status 2 ` Any help? TIA
Author
Owner

@paolafrancesca commented on GitHub:

it's a problem with curl: see man curl

              This transfers the specified local file to the remote URL. If there is no  file  part  in  the
              specified  URL,  curl  will append the local file name. NOTE that you must use a trailing / on
              the last directory to really prove to Curl that there is no file name or curl will think  that
              your  last  directory  name  is  the  remote file name to use. That will most likely cause the
              upload operation to fail. If this is used on an HTTP(S) server, the PUT command will be  used.

              Use  the file name "-" (a single dash) to use stdin instead of a given file.  Alternately, the
              file name "." (a single period) may be specified instead of "-" to use stdin  in  non-blocking
              mode to allow reading server output while stdin is being uploaded.

              You can specify one -T, --upload-file for each URL on the command line. Each -T, --upload-file
              + URL pair specifies what to upload and to where. curl also supports  "globbing"  of  the  -T,
              --upload-file  argument,  meaning  that you can upload multiple files to a single URL by using
              the same URL globbing style supported in the URL, like this:

               curl --upload-file "{file1,file2}" http://www.example.com

              or even

               curl -T "img[1-1000].png" ftp://ftp.example.com/upload/

globbing on -T doesn't seem to accept * wildcard. I'm able to execute curl -v --upload-file "test.{txt,log}" https://transfer.sh/ but not curl -v --upload-file "test*" https://transfer.sh/

@paolafrancesca commented on GitHub: it's a problem with curl: see `man curl` ``` -T, --upload-file <file> This transfers the specified local file to the remote URL. If there is no file part in the specified URL, curl will append the local file name. NOTE that you must use a trailing / on the last directory to really prove to Curl that there is no file name or curl will think that your last directory name is the remote file name to use. That will most likely cause the upload operation to fail. If this is used on an HTTP(S) server, the PUT command will be used. Use the file name "-" (a single dash) to use stdin instead of a given file. Alternately, the file name "." (a single period) may be specified instead of "-" to use stdin in non-blocking mode to allow reading server output while stdin is being uploaded. You can specify one -T, --upload-file for each URL on the command line. Each -T, --upload-file + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T, --upload-file argument, meaning that you can upload multiple files to a single URL by using the same URL globbing style supported in the URL, like this: curl --upload-file "{file1,file2}" http://www.example.com or even curl -T "img[1-1000].png" ftp://ftp.example.com/upload/ ``` globbing on -T doesn't seem to accept `*` wildcard. I'm able to execute `curl -v --upload-file "test.{txt,log}" https://transfer.sh/` but not `curl -v --upload-file "test*" https://transfer.sh/`
Author
Owner

@paolafrancesca commented on GitHub:

since you're in a python script you can glob from it and build an http put request directly in code

@paolafrancesca commented on GitHub: since you're in a python script you can glob from it and build an http put request directly in code
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#312