方法一:基于公钥和私钥的信任办法
ssh-keygen -t rsa
方法二:sshpass
下载地址:http://sourceforge.net/projects/sshpass/
yum -y install gcc
tar xf sshpass-1.06.tar.gz
./configure
make && make install
sshpass -p 密码 scp -r 1.txt root@10.1.1.1:/root
sshpass -f 存放密码的文件 scp -r 1.txt root@10.1.1.1:/root
方法三:python脚本
[root@localhost ~]# cat 1.py
#!/usr/bin/env python
import paramiko
import os
import datetime
hostname='10.1.1.132'
username='root'
password='redhat'
port=22
local_dir='/tmp/'
remote_dir='/tmp/test/'
if __name__=="__main__":
# try:
t=paramiko.Transport((hostname,port))
t.connect(username=username,password=password)
sftp=paramiko.SFTPClient.from_transport(t)
# files=sftp.listdir(dir_path)
files=os.listdir(local_dir)
for f in files:
print ''
print '#########################################'
print 'Beginning to upload file %s ' % datetime.datetime.now()
print 'Uploading file:',os.path.join(local_dir,f)
# sftp.get(os.path.join(dir_path,f),os.path.join(local_path,f))
sftp.put(os.path.join(local_dir,f),os.path.join(remote_dir,f))
print 'Upload file success %s ' % datetime.datetime.now()
print ''
print '##########################################'
#except Exception:
# print "error!"
t.close()