-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparamiko-tuto.py
50 lines (43 loc) · 1.52 KB
/
paramiko-tuto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import paramiko
import getpass
def check_pwd(address, port, usr, pwd):
try:
client = paramiko.client.SSHClient()
client.load_system_host_keys() # this loads any local ssh keys
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(address, port=port, username=usr, password=pwd)
client.close()
return True
except:
return False
def sftp(address, port, usr, pwd, fname):
print("sftp port " + str(port) + " of " + usr + "@" + address + ", transferring : " +
fname)
client = paramiko.client.SSHClient()
client.load_system_host_keys() # this loads any local ssh keys
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print('here')
client.connect(address, port=port, username=usr, password=pwd)
print('here')
sftp = client.open_sftp() # type SFTPClient
print('here')
print(sftp.put(fname, fname)) #src, dest path Documents/wikidata/
print('here')
client.close()
######"""YOUR INFO HERE"""######
address = ""
port = 22 #change if youre on a different wifi networek
username = ""
################################
# process to obtain remote password
authenticated = False
pwd = ''
while not authenticated:
pwd = getpass.getpass(prompt='sftp password: ')
authenticated = check_pwd(address, port, username, pwd)
if not authenticated:
print('authentication failed. try again')
else:
print('authenticated.')
#send example file
sftp(address, port, username, pwd, "ex.txt")