本文整理汇总了Python中paramiko.SFTPServer方法的典型用法代码示例。如果您正苦于以下问题:Python paramiko.SFTPServer方法的具体用法?Python paramiko.SFTPServer怎么用?Python paramiko.SFTPServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko
的用法示例。
在下文中一共展示了paramiko.SFTPServer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_server
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def start_server(host, port, keyfile, level):
paramiko_level = getattr(paramiko.common, level)
paramiko.common.logging.basicConfig(level=paramiko_level)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
server_socket.bind((host, port))
server_socket.listen(BACKLOG)
print host,port
while True:
conn, addr = server_socket.accept()
host_key = paramiko.RSAKey.from_private_key_file(keyfile)
transport = paramiko.Transport(conn)
transport.add_server_key(host_key)
transport.set_subsystem_handler(
'sftp', paramiko.SFTPServer, StubSFTPServer)
server = StubServer()
transport.start_server(server=server)
channel = transport.accept()
while transport.is_active():
time.sleep(1)
示例2: _start_sftp_server
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def _start_sftp_server():
"""Start the SFTP local server."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setblocking(False)
sock.bind(('localhost', 2222))
sock.listen(10)
reads = {sock}
others = set()
while not event.is_set():
ready_to_read, _, _ = select.select(reads, others, others, 1)
if sock in ready_to_read:
client_socket, address = sock.accept()
ts = paramiko.Transport(client_socket)
host_key = paramiko.RSAKey.from_private_key_file(t_path('server_id_rsa'))
ts.add_server_key(host_key)
server = StubServer()
ts.set_subsystem_handler('sftp', paramiko.SFTPServer, StubSFTPServer)
ts.start_server(server=server)
sock.close()
示例3: init_loopback
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def init_loopback():
global sftp, tc
socks = LoopSocket()
sockc = LoopSocket()
sockc.link(socks)
tc = paramiko.Transport(sockc)
ts = paramiko.Transport(socks)
host_key = paramiko.RSAKey.from_private_key_file(test_path('test_rsa.key'))
ts.add_server_key(host_key)
event = threading.Event()
server = StubServer()
ts.set_subsystem_handler('sftp', paramiko.SFTPServer, StubSFTPServer)
ts.start_server(event, server)
tc.connect(username='slowdive', password='pygmalion')
event.wait(1.0)
sftp = paramiko.SFTP.from_transport(tc)
示例4: _start_sftp_server
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def _start_sftp_server():
"""Start the SFTP local server."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setblocking(0)
sock.bind(('localhost', 2223))
sock.listen(10)
reads = {sock}
others = set()
while not event.is_set():
ready_to_read, _, _ = \
select.select(
reads,
others,
others,
1)
if sock in ready_to_read:
client_socket, address = sock.accept()
ts = paramiko.Transport(client_socket)
host_key = paramiko.RSAKey.from_private_key_file(
t_path('server_id_rsa')
)
ts.add_server_key(host_key)
server = StubServer()
ts.set_subsystem_handler(
'sftp', paramiko.SFTPServer, StubSFTPServer)
ts.start_server(server=server)
sock.close()
示例5: setUp
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def setUp(self):
"""Before running each test, create a server instance and create the required directories."""
self.server = SFTPServer(
SFTPServerProxyStorage(
"test:secret@localhost",
port=2223
),
logfile=t_path('log'),
raise_on_error=True
)
示例6: symlink
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def symlink(self, src, dest):
try:
os.symlink(src, dest)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
return paramiko.SFTP_OK
示例7: remove
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def remove(self, path):
try:
os.remove(path)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
return paramiko.SFTP_OK
示例8: mkdir
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def mkdir(self, path, attrs):
mode = getattr(attrs, 'st_mode', 0o777)
try:
os.mkdir(path, mode)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
return paramiko.SFTP_OK
示例9: rmdir
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def rmdir(self, path):
try:
os.rmdir(path)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
return paramiko.SFTP_OK
示例10: chattr
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def chattr(self, path, attrs):
if attrs.st_mode is not None:
try:
os.chmod(path, attrs.st_mode)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
if attrs.st_uid is not None:
try:
os.chown(path, attrs.st_uid, attrs.st_gid)
except OSError as e:
return SFTPServer.convert_errno(e.errno)
return paramiko.SFTP_OK
示例11: list_folder
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def list_folder(self, path):
"""Looks up folder contents of `path.`"""
# Inspired by https://github.com/rspivak/sftpserver/blob/0.3/src/sftpserver/stub_sftp.py#L70
try:
folder_contents = []
for f in os.listdir(path):
attr = paramiko.SFTPAttributes.from_stat(os.stat(os.path.join(path, f)))
attr.filename = f
folder_contents.append(attr)
return folder_contents
except OSError as e:
return SFTPServer.convert_errno(e.errno)
示例12: __init__
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def __init__(self, channel, name, server, sftp_si=SFTPServerInterface,
*largs, **kwargs):
kwargs["sftp_si"] = SFTPServerInterface
super(SFTPServer, self).__init__(channel, name, server, *largs,
**kwargs)
示例13: run_server
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import SFTPServer [as 别名]
def run_server(app, sock, hostkeys, username, pubkeys, homedir, cmdexe,
msg='Listening...'):
def update_text(n):
if n:
app.set_text(msg + '\n(Clients: %d)' % n)
else:
app.set_text(msg)
return
update_text(0)
sessions = []
while app.idle():
for session in sessions[:]:
session.idle()
ev = session.get_event()
if ev == 'open':
update_text(len(sessions))
app.show_balloon('Connected', session.get_name())
app.set_busy(True)
elif ev == 'closing':
session.close()
sessions.remove(session)
update_text(len(sessions))
app.show_balloon('Disconnected', session.get_name())
if not sessions:
app.set_busy(False)
elif ev == 'timeout':
sessions.remove(session)
try:
(conn, peer) = sock.accept()
except socket.timeout:
continue
conn.settimeout(0.05)
logging.info('Connected: addr=%r, port=%r' % peer)
t = paramiko.Transport(conn)
t.load_server_moduli()
#t.set_subsystem_handler('sftp', paramiko.SFTPServer)
for k in hostkeys:
t.add_server_key(k)
name = 'Session-%s-%s' % peer
server = PyRexecServer(username, pubkeys)
try:
t.start_server(server=server)
chan = t.accept(10)
if chan is not None:
session = PyRexecSession(app, name, chan, homedir, cmdexe, server)
sessions.append(session)
else:
logging.error('Timeout')
t.close()
except Exception as e:
logging.error('Error: %r' % e)
t.close()
while sessions:
session = sessions.pop()
session.close()
return
# main