How to run the sftp command with a password from Bash script?

后端 未结 9 750
礼貌的吻别
礼貌的吻别 2020-11-22 11:55

I need to transfer a log file to a remote host using sftp from a Linux host. I have been provided credentials for the same from my operations group. However, since I don\'t

9条回答
  •  佛祖请我去吃肉
    2020-11-22 12:45

    Another way would be to use lftp:

    lftp sftp://user:password@host  -e "put local-file.name; bye"
    

    The disadvantage of this method is that other users on the computer can read the password from tools like ps and that the password can become part of your shell history.

    A more secure alternative which is available since LFTP 4.5.0 is setting the LFTP_PASSWORDenvironment variable and executing lftp with --env-password. Here's a full example:

    LFTP_PASSWORD="just_an_example"
    lftp --env-password sftp://user@host  -e "put local-file.name; bye"
    

    LFTP also includes a cool mirroring feature (can include delete after confirmed transfer --Remove-source-files):

    lftp -e 'mirror -R /local/log/path/ /remote/path/' --env-password -u user sftp.foo.com
    

提交回复
热议问题