How to rename muliple files in SFTP using BASH script
I am a beginner to shell scripting.
I am trying to rename multiple files using wildcard in SFTP.
Please provide me some solution. or suggest some idea
My sh script:
sftp $userName@$hostName <<EOF
lcd $downloadPath
cd $rootpath
rename *.txt $rootpath/*.txt
exit
EOF
For this I got below error:
couldnt rename : no such file directory
bash sftp
add a comment |
I am a beginner to shell scripting.
I am trying to rename multiple files using wildcard in SFTP.
Please provide me some solution. or suggest some idea
My sh script:
sftp $userName@$hostName <<EOF
lcd $downloadPath
cd $rootpath
rename *.txt $rootpath/*.txt
exit
EOF
For this I got below error:
couldnt rename : no such file directory
bash sftp
HI Kamil, I added more details.
– pradeesh best
Mar 1 at 8:09
1
Are you bound to bash? If not, I'd looking into the Python 'paramiko' module, this can do it quite easily.
– Jeroen - IT Nerdbox
Mar 1 at 8:30
but i not knowing python scripting
– pradeesh best
Mar 1 at 9:17
Do not be afraid to learn new scripting languages. There are good examples out there. One of them is: github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
– Jeroen - IT Nerdbox
Mar 1 at 9:22
Since you seem to only want to move directories, there are graphical file managers (such as Dolphin) that can transparently access files via SFTP, and then moving the files can just be done by drag and drop. Alternatively, if you can access the files via SFTP you likely have access to the host via SSH so you can issue plain shell command in an SSH terminal session.
– xenoid
Mar 1 at 10:14
add a comment |
I am a beginner to shell scripting.
I am trying to rename multiple files using wildcard in SFTP.
Please provide me some solution. or suggest some idea
My sh script:
sftp $userName@$hostName <<EOF
lcd $downloadPath
cd $rootpath
rename *.txt $rootpath/*.txt
exit
EOF
For this I got below error:
couldnt rename : no such file directory
bash sftp
I am a beginner to shell scripting.
I am trying to rename multiple files using wildcard in SFTP.
Please provide me some solution. or suggest some idea
My sh script:
sftp $userName@$hostName <<EOF
lcd $downloadPath
cd $rootpath
rename *.txt $rootpath/*.txt
exit
EOF
For this I got below error:
couldnt rename : no such file directory
bash sftp
bash sftp
edited Mar 1 at 8:11
Kamil Maciorowski
28.8k156287
28.8k156287
asked Mar 1 at 7:58
pradeesh bestpradeesh best
11
11
HI Kamil, I added more details.
– pradeesh best
Mar 1 at 8:09
1
Are you bound to bash? If not, I'd looking into the Python 'paramiko' module, this can do it quite easily.
– Jeroen - IT Nerdbox
Mar 1 at 8:30
but i not knowing python scripting
– pradeesh best
Mar 1 at 9:17
Do not be afraid to learn new scripting languages. There are good examples out there. One of them is: github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
– Jeroen - IT Nerdbox
Mar 1 at 9:22
Since you seem to only want to move directories, there are graphical file managers (such as Dolphin) that can transparently access files via SFTP, and then moving the files can just be done by drag and drop. Alternatively, if you can access the files via SFTP you likely have access to the host via SSH so you can issue plain shell command in an SSH terminal session.
– xenoid
Mar 1 at 10:14
add a comment |
HI Kamil, I added more details.
– pradeesh best
Mar 1 at 8:09
1
Are you bound to bash? If not, I'd looking into the Python 'paramiko' module, this can do it quite easily.
– Jeroen - IT Nerdbox
Mar 1 at 8:30
but i not knowing python scripting
– pradeesh best
Mar 1 at 9:17
Do not be afraid to learn new scripting languages. There are good examples out there. One of them is: github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
– Jeroen - IT Nerdbox
Mar 1 at 9:22
Since you seem to only want to move directories, there are graphical file managers (such as Dolphin) that can transparently access files via SFTP, and then moving the files can just be done by drag and drop. Alternatively, if you can access the files via SFTP you likely have access to the host via SSH so you can issue plain shell command in an SSH terminal session.
– xenoid
Mar 1 at 10:14
HI Kamil, I added more details.
– pradeesh best
Mar 1 at 8:09
HI Kamil, I added more details.
– pradeesh best
Mar 1 at 8:09
1
1
Are you bound to bash? If not, I'd looking into the Python 'paramiko' module, this can do it quite easily.
– Jeroen - IT Nerdbox
Mar 1 at 8:30
Are you bound to bash? If not, I'd looking into the Python 'paramiko' module, this can do it quite easily.
– Jeroen - IT Nerdbox
Mar 1 at 8:30
but i not knowing python scripting
– pradeesh best
Mar 1 at 9:17
but i not knowing python scripting
– pradeesh best
Mar 1 at 9:17
Do not be afraid to learn new scripting languages. There are good examples out there. One of them is: github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
– Jeroen - IT Nerdbox
Mar 1 at 9:22
Do not be afraid to learn new scripting languages. There are good examples out there. One of them is: github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
– Jeroen - IT Nerdbox
Mar 1 at 9:22
Since you seem to only want to move directories, there are graphical file managers (such as Dolphin) that can transparently access files via SFTP, and then moving the files can just be done by drag and drop. Alternatively, if you can access the files via SFTP you likely have access to the host via SSH so you can issue plain shell command in an SSH terminal session.
– xenoid
Mar 1 at 10:14
Since you seem to only want to move directories, there are graphical file managers (such as Dolphin) that can transparently access files via SFTP, and then moving the files can just be done by drag and drop. Alternatively, if you can access the files via SFTP you likely have access to the host via SSH so you can issue plain shell command in an SSH terminal session.
– xenoid
Mar 1 at 10:14
add a comment |
1 Answer
1
active
oldest
votes
The sftp client is fairly basic, and won't execute loops or substitute variables. You have to
- Issue a first SFTP command that does a
lsof the directory, and capture its output - process that output to generate the list of rename command for each file
- Issue a second SFTP command with execute that list of rename commands
All in all, the alternatives are likely simpler.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1410396%2fhow-to-rename-muliple-files-in-sftp-using-bash-script%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
The sftp client is fairly basic, and won't execute loops or substitute variables. You have to
- Issue a first SFTP command that does a
lsof the directory, and capture its output - process that output to generate the list of rename command for each file
- Issue a second SFTP command with execute that list of rename commands
All in all, the alternatives are likely simpler.
add a comment |
The sftp client is fairly basic, and won't execute loops or substitute variables. You have to
- Issue a first SFTP command that does a
lsof the directory, and capture its output - process that output to generate the list of rename command for each file
- Issue a second SFTP command with execute that list of rename commands
All in all, the alternatives are likely simpler.
add a comment |
The sftp client is fairly basic, and won't execute loops or substitute variables. You have to
- Issue a first SFTP command that does a
lsof the directory, and capture its output - process that output to generate the list of rename command for each file
- Issue a second SFTP command with execute that list of rename commands
All in all, the alternatives are likely simpler.
The sftp client is fairly basic, and won't execute loops or substitute variables. You have to
- Issue a first SFTP command that does a
lsof the directory, and capture its output - process that output to generate the list of rename command for each file
- Issue a second SFTP command with execute that list of rename commands
All in all, the alternatives are likely simpler.
answered Mar 1 at 10:24
xenoidxenoid
3,9573719
3,9573719
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1410396%2fhow-to-rename-muliple-files-in-sftp-using-bash-script%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
HI Kamil, I added more details.
– pradeesh best
Mar 1 at 8:09
1
Are you bound to bash? If not, I'd looking into the Python 'paramiko' module, this can do it quite easily.
– Jeroen - IT Nerdbox
Mar 1 at 8:30
but i not knowing python scripting
– pradeesh best
Mar 1 at 9:17
Do not be afraid to learn new scripting languages. There are good examples out there. One of them is: github.com/paramiko/paramiko/blob/master/demos/demo_sftp.py
– Jeroen - IT Nerdbox
Mar 1 at 9:22
Since you seem to only want to move directories, there are graphical file managers (such as Dolphin) that can transparently access files via SFTP, and then moving the files can just be done by drag and drop. Alternatively, if you can access the files via SFTP you likely have access to the host via SSH so you can issue plain shell command in an SSH terminal session.
– xenoid
Mar 1 at 10:14