How to rename muliple files in SFTP using BASH script












0















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









share|improve this question

























  • 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
















0















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









share|improve this question

























  • 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














0












0








0








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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










1 Answer
1






active

oldest

votes


















1














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 ls of 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.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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 ls of 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.






    share|improve this answer




























      1














      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 ls of 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.






      share|improve this answer


























        1












        1








        1







        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 ls of 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.






        share|improve this answer













        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 ls of 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 1 at 10:24









        xenoidxenoid

        3,9573719




        3,9573719






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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

            Index of /

            Tribalistas

            Listed building