Sheell Script for SFTP - Redhat

This is a discussion on Sheell Script for SFTP - Redhat ; Hi All, I am looking for a shell script for SFTP a file and not prompting for the password. I wrote the small script but it doesn't work. I am trying to download the file by name test located at ...

+ Reply to Thread
Results 1 to 12 of 12

Thread: Sheell Script for SFTP

  1. Sheell Script for SFTP

    Hi All,

    I am looking for a shell script for SFTP a file and not prompting for the
    password.
    I wrote the small script but it doesn't work. I am trying to download the
    file by name test located at /root directory on System with IP 10.77.31.202.
    The userid and password of 10.77.31.202 is root and venkat. Could some one
    correct this please.

    #! /bin/sh

    HOST='10.77.31.202'
    USER='root'
    PASSWD='venkat'

    ftp $HOST
    user ${USER} ${PASSWD}

    cd /root/
    get test

    exit 0


    Regards,
    Venkat



  2. Re: Sheell Script for SFTP

    "Venkat" writes:

    > I am looking for a shell script for SFTP a file and not prompting for the
    > password.


    Expect used to be the answer. Perl/python/ruby are probably good
    alternatives these days. Sh/csh/bash/zsh etc are usually tricky as front
    end to interactive programs.

    > #! /bin/sh
    > ...
    > ftp $HOST
    > user ${USER} ${PASSWD}
    >
    > cd /root/
    > get test
    >
    > exit 0


    The lines after the ftp line are not sent to ftp but to the shell, after
    ftp finishes, which probably never happens in your script ...

    -- HASM

  3. Re: Sheell Script for SFTP

    > > #! /bin/sh
    > > ...
    > > ftp $HOST
    > > user ${USER} ${PASSWD}
    > >
    > > cd /root/
    > > get test
    > >
    > > exit 0

    >
    > The lines after the ftp line are not sent to ftp but to the shell, after
    > ftp finishes, which probably never happens in your script ...
    >
    > -- HASM


    Thanks HASM for an immediate response. I modified it the below
    sftp $HOST user ${USER} ${PASSWD}
    and this doesn't work as the format for sftp is different and more over get
    command doesn't work in .sh.
    I am looking is it possible to write a script to sftp a file without need to
    prompt a password.

    Any suggestions are highly appreciated.

    Regards,
    Venkat




  4. Re: Sheell Script for SFTP

    "Venkat" writes:

    > Any suggestions are highly appreciated.


    I would give up trying to right a shell script (whatever shell) to interact
    with interactive programs. There's too many pitfalls.

    Look at the man page for sftp, I'm not sure what you're trying to do
    exactly but sftp may handle it just by itself, in the form
    sftp -b batchfile [user@]host

    Again, If I had to automate something like that I would use Perl, Python,
    Ruby or Expect, not a shell script.

    -- HASM

  5. Re: Sheell Script for SFTP

    On Thu, 1 Sep 2005 20:05:18 +0530, "Venkat"
    wrote:

    >Hi All,
    >
    >I am looking for a shell script for SFTP a file and not prompting for the
    >password.
    >I wrote the small script but it doesn't work. I am trying to download the
    >file by name test located at /root directory on System with IP 10.77.31.202.
    >The userid and password of 10.77.31.202 is root and venkat. Could some one
    >correct this please.
    >
    >#! /bin/sh
    >
    >HOST='10.77.31.202'
    >USER='root'
    >PASSWD='venkat'
    >
    >ftp $HOST
    >user ${USER} ${PASSWD}
    >
    >cd /root/
    >get test
    >
    >exit 0
    >
    >
    >Regards,
    >Venkat
    >

    Have you tried using a here document? I'm not that familiar with
    sftp, but perhaps you could make this more secure and get around the
    password by using RSA authentication.

    #! /bin/sh

    HOST='10.77.31.202'
    USER='root'
    PASSWD='venkat'

    ftp $HOST< user ${USER} ${PASSWD}

    cd /root/
    get test

    exit 0
    EOF

  6. Re: Sheell Script for SFTP

    "Ian East" wrote in message
    news:tdleh11qi5ddh4pmtfaerta7ask2e4g8js@4ax.com...

    > Have you tried using a here document? I'm not that familiar with
    > sftp, but perhaps you could make this more secure and get around the
    > password by using RSA authentication.
    >
    > #! /bin/sh
    >
    > HOST='10.77.31.202'
    > USER='root'
    > PASSWD='venkat'
    >
    > ftp $HOST< > user ${USER} ${PASSWD}
    >
    > cd /root/
    > get test
    >
    > exit 0
    > EOF


    Thanks Ian. But didn't worked. Any other way?

    Regards,
    Venkat



  7. Re: Sheell Script for SFTP


    > Have you tried using a here document?


    Here documents passed to interactive programs usually don't work, as they
    may not be passed through line at a time, tty style, when the program needs
    them, and at the end of the document usually stdin closes potentially
    causing the program to terminate

    > I'm not that familiar with sftp, but perhaps you could make this more
    > secure and get around the password by using RSA authentication.


    Obviously, passwords in scripts are not that secure.

    Something like this may work better

    #!/bin/sh
    HOST='10.77.31.202'
    USER='root'
    PASSWD='venkat'

    sftp -b - ${USER}@${HOST} << EOF
    ${PASSWD}
    cd /root
    get test
    exit
    EOF

  8. Re: Sheell Script for SFTP

    On Fri, 2 Sep 2005 18:28:08 +0530, "Venkat"
    wrote:

    >"Ian East" wrote in message
    >news:tdleh11qi5ddh4pmtfaerta7ask2e4g8js@4ax.com...
    >
    >> Have you tried using a here document? I'm not that familiar with
    >> sftp, but perhaps you could make this more secure and get around the
    >> password by using RSA authentication.
    >>
    >> #! /bin/sh
    >>
    >> HOST='10.77.31.202'
    >> USER='root'
    >> PASSWD='venkat'
    >>
    >> ftp $HOST< >> user ${USER} ${PASSWD}
    >>
    >> cd /root/
    >> get test
    >>
    >> exit 0
    >> EOF

    >
    >Thanks Ian. But didn't worked. Any other way?
    >
    >Regards,
    >Venkat
    >


    whoops.. forgot you need to use the -n flag to disable auto-login if
    you want to use a here document.

    ftp -n $HOST<

  9. Re: Sheell Script for SFTP

    .... after inserting a credit, Venkat leaned forward
    and saw...
    >
    >Thanks Ian. But didn't worked. Any other way?
    >

    Does .netrc not work for sftp?

    Failing that, can you wget over SSL?
    --
    "I call up my friend, the good angel
    But she's out with her answerphone."

  10. Re: Sheell Script for SFTP

    > whoops.. forgot you need to use the -n flag to disable auto-login if
    > you want to use a here document.
    >
    > ftp -n $HOST<

    Hi Ian,

    This is what i tried but when i execute ./prg1.sh it hangs

    #!/bin/sh
    HOST='10.77.31.202'
    USER='root'
    PASSWD='venkat'

    ftp -n ${HOST} << EOF
    user {$USER} ${PASSWD}
    cd /root
    get test
    exit 0
    EOF


    Regards,
    Venkat



  11. Re: Sheell Script for SFTP


    exit 0 will not work in ftp. use bye instead.

    #!/bin/sh
    HOST='10.77.31.202'
    USER='root'
    PASSWD='venkat'

    ftp -n ${HOST} << EOF
    user {$USER} ${PASSWD}
    cd /root
    get test
    bye
    EO

    --
    artsyla
    -----------------------------------------------------------------------
    artsylar's Profile: http://usenetlinux.com/member.php?userid=505
    View this thread: http://usenetlinux.com/showthread.php?t=47223


  12. Re: Sheell Script for SFTP


    or you can also use quit instead of exit

    --
    artsyla
    -----------------------------------------------------------------------
    artsylar's Profile: http://usenetlinux.com/member.php?userid=505
    View this thread: http://usenetlinux.com/showthread.php?t=47223