指定密码在Bash脚本为sftp [英] Specify password to sftp in a Bash script

查看:384
本文介绍了指定密码在Bash脚本为sftp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个脚本来备份文件过SFTP。问题是,它需要一个密码,我看不出有什么办法来手动指定密码SFTP。我听说过,需要使用公共密钥没有密码,但需要能够ssh到远程服务器,并修改一些配置文件,这一点我是做不到的。

I am trying to write a script to back up a file over SFTP. The problem is, it requires a password, and I see no way to manually specify a password to SFTP. I've heard about requiring no password by using public keys, but that requires being able to ssh into the remote server and modify some configuration files, which I cannot do.

目前我的解决方法是使用卷曲,但是这是不安全的(正常使用FTP)。我又看了看的.netrc 文件,但是这似乎是FTP,而不是SFTP。如何手动为SFTP指定密码吗?

Currently my solution is to use cURL, but that is insecure (uses normal FTP). I also looked at the .netrc file, but that seems to be for FTP instead of SFTP. How do I manually specify a password for sftp?

推荐答案

LFTP允许指定的FTP和SFTP密码,也不需要公钥的。您的SH同步脚本可能是这样的:

Lftp allows specifying passwords for both ftp and sftp and does not require public keys at all. Your sh sync script may look like this:

#!/bin/sh
# Define folders
THEFOLDER='/mnt/my/folder'
# List files
THEFILES=`ls -p $THEFOLDER | grep -v "/"`

for file in $THEFILES
do
  echo "Processing $file"
  lftp -u login,password -e "put $THEFOLDER/$file;quit"  theftp/sub/folder
done

这篇关于指定密码在Bash脚本为sftp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆