SFTP Node.js - Is it possible to list files using wildcards?
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
add a comment |
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
add a comment |
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
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
node.js sftp ssh2-sftp
asked Nov 23 '18 at 13:53
GeorgeBT1902GeorgeBT1902
768
768
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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