将本地指定路径下的文件上传到服务器指定目录
# -*- coding: UTF-8 -*-
#!/usr/bin/python
'''
注意name_lst中的steam账号cookie文件的名称要与账号相对应
'''
import paramiko
import os
name_lst = [
# 'BuffSearch.py',
# 'BuyManager.py',
# 'Cryptoo.py',
# 'DownloadServerScrapyData.py',
# 'Initial.py',
# 'MakeSubscripData.py',
#
# 'MarketBuy.py',
# 'ParseData.py',
# 'SteamAutoBuy.py',
# 'SteamSearchClient.py',
# 'SteamWebLogin.py',
# 'WebSess.py',
'buff_mobile_cookie.json',
# 'category_name_lst.json',
# 'filter_config.json',
# '1156521784.json',
]
ip = '000.000.000' ###服务器ip
port = '22'
username = 'root'
password = '554546466'
class Paramiko_put(object):
def __init__(self,host,username,passwd,local_dir,remote_dir,port):
self.host = host
self.username = username
self.passwd = passwd
self.port = int(port)
self.local_dir = local_dir
self.remote_dir = remote_dir
self.tt = None
self.sftp = self.pk_connect()
def pk_connect(self):
self.tt = paramiko.Transport((self.host, self.port))
self.tt.connect(username = self.username, password = self.passwd)
try:
return paramiko.SFTPClient.from_transport(self.tt)
except Exception as e:
print ('Connect error:',e)
exit()
def put_file(self,local_file_name,remote_file_name):
self.sftp.put(os.path.join(self.local_dir,local_file_name), os.path.join(self.remote_dir, remote_file_name))
def __del__(self):
try:
self.tt.close()
except:
pass
if __name__ == '__main__':
print('\nconnect...')
try:
pk = Paramiko_put(ip,
username,
password,
os.getcwd(),
# '/home/yf//',
'/home/steambuy//',
port
)
for name in name_lst:
pk.put_file(name,name)
print(name,'ok')
except Exception as e:
print('Error-move-file-to-server:',e)