SFTP Node.js - Is it possible to list files using wildcards?












0















I'm trying to list all files in my SFTP server from a top level folder in Node.js using the npm module ssh2-sftp-client. However, I cannot find any documentation or previous posts which discuss whether using a wildcards in the file paths is possible. The file paths look like so:



../mnt/volume_lon1_01/currency/curve/date/filename.csv


There can be many different currencies, curves and dates - Hundreds in fact - I need a means of just listing every file name at the final level of the file structure.



I thought a sensible approach would be to use wildcards:



../mnt/volume_lon1_01/ * / * / * / *.csv


But this doesn't seem to work and I can't find anything to suggest it could. Can anyone advise how would be best to list every file from SFTP in Node.js?



Many thanks,



George










share|improve this question



























    0















    I'm trying to list all files in my SFTP server from a top level folder in Node.js using the npm module ssh2-sftp-client. However, I cannot find any documentation or previous posts which discuss whether using a wildcards in the file paths is possible. The file paths look like so:



    ../mnt/volume_lon1_01/currency/curve/date/filename.csv


    There can be many different currencies, curves and dates - Hundreds in fact - I need a means of just listing every file name at the final level of the file structure.



    I thought a sensible approach would be to use wildcards:



    ../mnt/volume_lon1_01/ * / * / * / *.csv


    But this doesn't seem to work and I can't find anything to suggest it could. Can anyone advise how would be best to list every file from SFTP in Node.js?



    Many thanks,



    George










    share|improve this question

























      0












      0








      0








      I'm trying to list all files in my SFTP server from a top level folder in Node.js using the npm module ssh2-sftp-client. However, I cannot find any documentation or previous posts which discuss whether using a wildcards in the file paths is possible. The file paths look like so:



      ../mnt/volume_lon1_01/currency/curve/date/filename.csv


      There can be many different currencies, curves and dates - Hundreds in fact - I need a means of just listing every file name at the final level of the file structure.



      I thought a sensible approach would be to use wildcards:



      ../mnt/volume_lon1_01/ * / * / * / *.csv


      But this doesn't seem to work and I can't find anything to suggest it could. Can anyone advise how would be best to list every file from SFTP in Node.js?



      Many thanks,



      George










      share|improve this question














      I'm trying to list all files in my SFTP server from a top level folder in Node.js using the npm module ssh2-sftp-client. However, I cannot find any documentation or previous posts which discuss whether using a wildcards in the file paths is possible. The file paths look like so:



      ../mnt/volume_lon1_01/currency/curve/date/filename.csv


      There can be many different currencies, curves and dates - Hundreds in fact - I need a means of just listing every file name at the final level of the file structure.



      I thought a sensible approach would be to use wildcards:



      ../mnt/volume_lon1_01/ * / * / * / *.csv


      But this doesn't seem to work and I can't find anything to suggest it could. Can anyone advise how would be best to list every file from SFTP in Node.js?



      Many thanks,



      George







      node.js sftp ssh2-sftp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 13:53









      GeorgeBT1902GeorgeBT1902

      768




      768
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Mmm, I don't think this is possible in ssh2, but what you can do is list them algorithmically and access each one, pseudo-code:



          Connect SFTP
          List Folders -> Save this to a dictionary
          For each folder in Folders
          List Folders - > Save this to a dictionary


          At the end of it you'll have a dictionary object with the full path of the remote server, like so



          {
          sftp: {
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          ...
          }
          }
          }
          }
          }
          }
          }


          From that you can easily access whatever you need by doing



          sftp["/rootfolder"]["/subfolder1"]... etc





          share|improve this answer
























          • Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

            – Sergio Flores
            Nov 23 '18 at 16:01











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53447984%2fsftp-node-js-is-it-possible-to-list-files-using-wildcards%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









          1














          Mmm, I don't think this is possible in ssh2, but what you can do is list them algorithmically and access each one, pseudo-code:



          Connect SFTP
          List Folders -> Save this to a dictionary
          For each folder in Folders
          List Folders - > Save this to a dictionary


          At the end of it you'll have a dictionary object with the full path of the remote server, like so



          {
          sftp: {
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          ...
          }
          }
          }
          }
          }
          }
          }


          From that you can easily access whatever you need by doing



          sftp["/rootfolder"]["/subfolder1"]... etc





          share|improve this answer
























          • Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

            – Sergio Flores
            Nov 23 '18 at 16:01
















          1














          Mmm, I don't think this is possible in ssh2, but what you can do is list them algorithmically and access each one, pseudo-code:



          Connect SFTP
          List Folders -> Save this to a dictionary
          For each folder in Folders
          List Folders - > Save this to a dictionary


          At the end of it you'll have a dictionary object with the full path of the remote server, like so



          {
          sftp: {
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          ...
          }
          }
          }
          }
          }
          }
          }


          From that you can easily access whatever you need by doing



          sftp["/rootfolder"]["/subfolder1"]... etc





          share|improve this answer
























          • Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

            – Sergio Flores
            Nov 23 '18 at 16:01














          1












          1








          1







          Mmm, I don't think this is possible in ssh2, but what you can do is list them algorithmically and access each one, pseudo-code:



          Connect SFTP
          List Folders -> Save this to a dictionary
          For each folder in Folders
          List Folders - > Save this to a dictionary


          At the end of it you'll have a dictionary object with the full path of the remote server, like so



          {
          sftp: {
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          ...
          }
          }
          }
          }
          }
          }
          }


          From that you can easily access whatever you need by doing



          sftp["/rootfolder"]["/subfolder1"]... etc





          share|improve this answer













          Mmm, I don't think this is possible in ssh2, but what you can do is list them algorithmically and access each one, pseudo-code:



          Connect SFTP
          List Folders -> Save this to a dictionary
          For each folder in Folders
          List Folders - > Save this to a dictionary


          At the end of it you'll have a dictionary object with the full path of the remote server, like so



          {
          sftp: {
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          "0": {
          "name": "/rootfolder",
          "subfolders": {
          ...
          }
          }
          }
          }
          }
          }
          }


          From that you can easily access whatever you need by doing



          sftp["/rootfolder"]["/subfolder1"]... etc






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 15:50









          Sergio FloresSergio Flores

          1126




          1126













          • Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

            – Sergio Flores
            Nov 23 '18 at 16:01



















          • Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

            – Sergio Flores
            Nov 23 '18 at 16:01

















          Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

          – Sergio Flores
          Nov 23 '18 at 16:01





          Actually, if you don't need the specific subfolders, you can just drill down through them using the above to reach the lowest level files, basically list, forEach, list again, till there aren't any more subfolders

          – Sergio Flores
          Nov 23 '18 at 16:01


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f53447984%2fsftp-node-js-is-it-possible-to-list-files-using-wildcards%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

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python