Uploading multiple files via FTP using curl












11















I'm trying to upload all the text files within the current folder via FTP to a server location using curl. I tried the following line:



 curl -T "{file1.txt, file2.txt}" ftp://XXX --user YYY


where XXX is the server's IP address and YYY is the username and password.



I'm able to transfer file1.txt to the server successfully, but it complains about the second file saying 'Can't open 'file_name'!'



I swapped the file names and it worked for file2.txt and not file1.txt. Seems like I've got the syntax wrong, but this is what the manual says?



Also, ideally I would be able to do something like this:



 curl -T *.txt ftp://XXX --user YYY


because I won't always know the names of the txt files in the current folder or the number of files to be transferred.



I'm of the opinion I may have to write a bash script that collects the output of ls *.txt into an array and put it into the multiple-files-format required by curl.



I've not done bash scripting before - is this the simplest way to achieve this?










share|improve this question





























    11















    I'm trying to upload all the text files within the current folder via FTP to a server location using curl. I tried the following line:



     curl -T "{file1.txt, file2.txt}" ftp://XXX --user YYY


    where XXX is the server's IP address and YYY is the username and password.



    I'm able to transfer file1.txt to the server successfully, but it complains about the second file saying 'Can't open 'file_name'!'



    I swapped the file names and it worked for file2.txt and not file1.txt. Seems like I've got the syntax wrong, but this is what the manual says?



    Also, ideally I would be able to do something like this:



     curl -T *.txt ftp://XXX --user YYY


    because I won't always know the names of the txt files in the current folder or the number of files to be transferred.



    I'm of the opinion I may have to write a bash script that collects the output of ls *.txt into an array and put it into the multiple-files-format required by curl.



    I've not done bash scripting before - is this the simplest way to achieve this?










    share|improve this question



























      11












      11








      11


      2






      I'm trying to upload all the text files within the current folder via FTP to a server location using curl. I tried the following line:



       curl -T "{file1.txt, file2.txt}" ftp://XXX --user YYY


      where XXX is the server's IP address and YYY is the username and password.



      I'm able to transfer file1.txt to the server successfully, but it complains about the second file saying 'Can't open 'file_name'!'



      I swapped the file names and it worked for file2.txt and not file1.txt. Seems like I've got the syntax wrong, but this is what the manual says?



      Also, ideally I would be able to do something like this:



       curl -T *.txt ftp://XXX --user YYY


      because I won't always know the names of the txt files in the current folder or the number of files to be transferred.



      I'm of the opinion I may have to write a bash script that collects the output of ls *.txt into an array and put it into the multiple-files-format required by curl.



      I've not done bash scripting before - is this the simplest way to achieve this?










      share|improve this question
















      I'm trying to upload all the text files within the current folder via FTP to a server location using curl. I tried the following line:



       curl -T "{file1.txt, file2.txt}" ftp://XXX --user YYY


      where XXX is the server's IP address and YYY is the username and password.



      I'm able to transfer file1.txt to the server successfully, but it complains about the second file saying 'Can't open 'file_name'!'



      I swapped the file names and it worked for file2.txt and not file1.txt. Seems like I've got the syntax wrong, but this is what the manual says?



      Also, ideally I would be able to do something like this:



       curl -T *.txt ftp://XXX --user YYY


      because I won't always know the names of the txt files in the current folder or the number of files to be transferred.



      I'm of the opinion I may have to write a bash script that collects the output of ls *.txt into an array and put it into the multiple-files-format required by curl.



      I've not done bash scripting before - is this the simplest way to achieve this?







      shell-script ftp curl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 7 at 15:36









      Matthias Braun

      2,04921424




      2,04921424










      asked Oct 10 '16 at 11:12









      JJTJJT

      58117




      58117






















          1 Answer
          1






          active

          oldest

          votes


















          13














          Your first command should work without whitespaces:



          curl -T "{file1.txt,file2.txt}" ftp://XXX/ -user YYY


          Also note the trailing "/" in the URLs above.



          This is curl's manual entry about option "-T":




          -T, --upload-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 for each URL on the command line. Each -T + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T
          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 -T "{file1,file2}" http://www.uploadtothissite.com


          or even



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



          "*.txt" expansion does not work because curl supports only the same syntax as for URLs:




          You can specify multiple URLs or parts of URLs by writing part sets within braces as in:



          http://site.{one,two,three}.com



          or you can get sequences of alphanumeric series by using as in:



          ftp://ftp.numericals.com/file[1-100].txt



          ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)



          ftp://ftp.letters.com/file[a-z].txt



          [...]



          When using or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'.




          But you could use the "normal" shell globbing like this:



          curl -T "{$(echo *.txt | tr ' ' ',')}" ftp://XXX/ -user YYY


          (The last example may not work in all shells or with any kind of exotic file names.)






          share|improve this answer


























          • Wow, very descriptive answer. Thanks :)

            – John Skoumbourdis
            Nov 11 '18 at 19:01











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f315424%2fuploading-multiple-files-via-ftp-using-curl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          13














          Your first command should work without whitespaces:



          curl -T "{file1.txt,file2.txt}" ftp://XXX/ -user YYY


          Also note the trailing "/" in the URLs above.



          This is curl's manual entry about option "-T":




          -T, --upload-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 for each URL on the command line. Each -T + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T
          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 -T "{file1,file2}" http://www.uploadtothissite.com


          or even



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



          "*.txt" expansion does not work because curl supports only the same syntax as for URLs:




          You can specify multiple URLs or parts of URLs by writing part sets within braces as in:



          http://site.{one,two,three}.com



          or you can get sequences of alphanumeric series by using as in:



          ftp://ftp.numericals.com/file[1-100].txt



          ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)



          ftp://ftp.letters.com/file[a-z].txt



          [...]



          When using or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'.




          But you could use the "normal" shell globbing like this:



          curl -T "{$(echo *.txt | tr ' ' ',')}" ftp://XXX/ -user YYY


          (The last example may not work in all shells or with any kind of exotic file names.)






          share|improve this answer


























          • Wow, very descriptive answer. Thanks :)

            – John Skoumbourdis
            Nov 11 '18 at 19:01
















          13














          Your first command should work without whitespaces:



          curl -T "{file1.txt,file2.txt}" ftp://XXX/ -user YYY


          Also note the trailing "/" in the URLs above.



          This is curl's manual entry about option "-T":




          -T, --upload-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 for each URL on the command line. Each -T + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T
          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 -T "{file1,file2}" http://www.uploadtothissite.com


          or even



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



          "*.txt" expansion does not work because curl supports only the same syntax as for URLs:




          You can specify multiple URLs or parts of URLs by writing part sets within braces as in:



          http://site.{one,two,three}.com



          or you can get sequences of alphanumeric series by using as in:



          ftp://ftp.numericals.com/file[1-100].txt



          ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)



          ftp://ftp.letters.com/file[a-z].txt



          [...]



          When using or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'.




          But you could use the "normal" shell globbing like this:



          curl -T "{$(echo *.txt | tr ' ' ',')}" ftp://XXX/ -user YYY


          (The last example may not work in all shells or with any kind of exotic file names.)






          share|improve this answer


























          • Wow, very descriptive answer. Thanks :)

            – John Skoumbourdis
            Nov 11 '18 at 19:01














          13












          13








          13







          Your first command should work without whitespaces:



          curl -T "{file1.txt,file2.txt}" ftp://XXX/ -user YYY


          Also note the trailing "/" in the URLs above.



          This is curl's manual entry about option "-T":




          -T, --upload-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 for each URL on the command line. Each -T + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T
          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 -T "{file1,file2}" http://www.uploadtothissite.com


          or even



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



          "*.txt" expansion does not work because curl supports only the same syntax as for URLs:




          You can specify multiple URLs or parts of URLs by writing part sets within braces as in:



          http://site.{one,two,three}.com



          or you can get sequences of alphanumeric series by using as in:



          ftp://ftp.numericals.com/file[1-100].txt



          ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)



          ftp://ftp.letters.com/file[a-z].txt



          [...]



          When using or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'.




          But you could use the "normal" shell globbing like this:



          curl -T "{$(echo *.txt | tr ' ' ',')}" ftp://XXX/ -user YYY


          (The last example may not work in all shells or with any kind of exotic file names.)






          share|improve this answer















          Your first command should work without whitespaces:



          curl -T "{file1.txt,file2.txt}" ftp://XXX/ -user YYY


          Also note the trailing "/" in the URLs above.



          This is curl's manual entry about option "-T":




          -T, --upload-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 for each URL on the command line. Each -T + URL pair specifies what to upload and to where. curl also supports "globbing" of the -T
          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 -T "{file1,file2}" http://www.uploadtothissite.com


          or even



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



          "*.txt" expansion does not work because curl supports only the same syntax as for URLs:




          You can specify multiple URLs or parts of URLs by writing part sets within braces as in:



          http://site.{one,two,three}.com



          or you can get sequences of alphanumeric series by using as in:



          ftp://ftp.numericals.com/file[1-100].txt



          ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)



          ftp://ftp.letters.com/file[a-z].txt



          [...]



          When using or {} sequences when invoked from a command line prompt, you probably have to put the full URL within double quotes to avoid the shell from interfering with it. This also goes for other characters treated special, like for example '&', '?' and '*'.




          But you could use the "normal" shell globbing like this:



          curl -T "{$(echo *.txt | tr ' ' ',')}" ftp://XXX/ -user YYY


          (The last example may not work in all shells or with any kind of exotic file names.)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 7 at 14:51









          Matthias Braun

          2,04921424




          2,04921424










          answered Oct 10 '16 at 11:57









          rudimeierrudimeier

          5,5171832




          5,5171832













          • Wow, very descriptive answer. Thanks :)

            – John Skoumbourdis
            Nov 11 '18 at 19:01



















          • Wow, very descriptive answer. Thanks :)

            – John Skoumbourdis
            Nov 11 '18 at 19:01

















          Wow, very descriptive answer. Thanks :)

          – John Skoumbourdis
          Nov 11 '18 at 19:01





          Wow, very descriptive answer. Thanks :)

          – John Skoumbourdis
          Nov 11 '18 at 19:01


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f315424%2fuploading-multiple-files-via-ftp-using-curl%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

          is 'sed' thread safe

          How to make a Squid Proxy server?