add ssh transfer
This commit is contained in:
parent
36d6899692
commit
e4e4beac3a
@ -8,17 +8,55 @@ import stat
|
||||
import popen2
|
||||
import glob
|
||||
import sys
|
||||
import os
|
||||
import pprint
|
||||
import base64
|
||||
import getpass
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import traceback
|
||||
import paramiko
|
||||
|
||||
|
||||
from subprocess import Popen
|
||||
|
||||
paramiko.util.log_to_file('demo_sftp.log')
|
||||
|
||||
path = "/Users/david/Devel/arch/avr/code/snesram/roms/"
|
||||
|
||||
if os.name == 'posix':
|
||||
path = "/home/david/Devel/arch/avr/code/snesram/roms/"
|
||||
username = "david"
|
||||
hostname = "slap"
|
||||
else:
|
||||
path = "/Users/david/Devel/arch/avr/code/snesram/roms/"
|
||||
username = "david"
|
||||
hostname = "burst"
|
||||
|
||||
def shellquote(s):
|
||||
return "'" + s.replace("'", "'\\''") + "'"
|
||||
|
||||
def main():
|
||||
|
||||
port = 22
|
||||
password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
|
||||
hostkeytype = None
|
||||
hostkey = None
|
||||
host_keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
|
||||
if host_keys.has_key(hostname):
|
||||
hostkeytype = host_keys[hostname].keys()[0]
|
||||
hostkey = host_keys[hostname][hostkeytype]
|
||||
print 'Using host key of type %s' % hostkeytype
|
||||
try:
|
||||
print "Connect %s:%s" % (hostname, port)
|
||||
t = paramiko.Transport((hostname, port))
|
||||
t.connect(username=username, password=password, hostkey=hostkey)
|
||||
sftp = paramiko.SFTPClient.from_transport(t)
|
||||
|
||||
# dirlist on remote host
|
||||
dirlist = sftp.listdir('.')
|
||||
print "Dirlist:", dirlist
|
||||
|
||||
|
||||
conn = sqlite3.connect('roms.sqlite3')
|
||||
c = conn.cursor()
|
||||
for i in [(4,),(8,),(16,),(32,)]:
|
||||
@ -48,15 +86,20 @@ def main():
|
||||
''',i)
|
||||
for row in c:
|
||||
name,size,filename = row
|
||||
if '[' not in filename:
|
||||
src = "david@burst:%s" % filename
|
||||
command = ["scp",shellquote(src), dirname]
|
||||
proc = Popen(command)
|
||||
print dir(proc)
|
||||
proc.communicate()
|
||||
filename_dst = os.path.join(dirname,os.path.basename(filename))
|
||||
print "Remote: %s -> %s" % ( filename,filename_dst)
|
||||
data = open(filename, 'r').read()
|
||||
open(filename_dst,"w").write(data)
|
||||
|
||||
except Exception, e:
|
||||
print '*** Caught exception: %s: %s' % (e.__class__, e)
|
||||
traceback.print_exc()
|
||||
try:
|
||||
t.close()
|
||||
except:
|
||||
pass
|
||||
sys.exit(1)
|
||||
|
||||
raise
|
||||
>>>>>>> b7b35800ccc7b48d24cfd4c3e025482e95e3fc72:scripts/query_romsize.py
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user