-
Notifications
You must be signed in to change notification settings - Fork 18
/
paramiko-test
executable file
·48 lines (36 loc) · 1.06 KB
/
paramiko-test
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
#! /usr/bin/env python3
import socket,subprocess,os
import paramiko
hostname = os.getenv("SELF", socket.gethostname())
print("+ cleanup")
os.system("rm -rf ,ptestroot")
print("+ creating client")
ssh = paramiko.SSHClient()
print("+ loading host keys")
ssh.load_host_keys("%s/.ssh/known_hosts" % os.getenv("HOME"))
print("+ connecting to: %s" % hostname)
ssh.connect(hostname)
print("+ opening SFTP session")
c = ssh.open_sftp()
print("+ chdir to: %s" % os.getcwd())
c.chdir(os.getcwd())
print("+ comparing file list")
remote_files = c.listdir(".")
remote_files.sort()
local_files = os.listdir(".")
local_files.sort()
assert remote_files == local_files
print("+ creating test directory")
c.mkdir(",ptestroot")
print("+ chdir to test directory")
c.chdir(",ptestroot")
os.chdir(",ptestroot")
print("+ check test directory is empty")
assert c.listdir(".") == []
print("+ upload a file")
c.put("../gesftpserver", "uploaded")
print("+ check it arrived")
print("++ via local")
assert os.listdir(".") == ["uploaded"]
print("++ via paramiko")
assert c.listdir(".") == ["uploaded"]