Commit c5d09ac3 by willmcgugan

Docstrings and fixes for sftp server

parent 742ff4a6
......@@ -57,6 +57,16 @@ Serves the contents of PATH with one of a number of methods"""
elif options.type == 'sftp':
from fs.expose.sftp import BaseSFTPServer
import logging
log = logging.getLogger('paramiko')
if options.debug:
log.setLevel(logging.DEBUG)
elif options.verbose:
log.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)
if port is None:
port = 22
server = BaseSFTPServer((options.addr, port), fs)
......
__all__ = ["serve_fs"]
import SimpleHTTPServer
import SocketServer
from fs.path import pathjoin, dirname
......@@ -128,6 +130,14 @@ class FSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def serve_fs(fs, address='', port=8000):
"""Serve an FS instance over http
:param fs: an FS object
:param address: IP address to serve on
:param port: port number
"""
def Handler(request, client_address, server):
return FSHTTPRequestHandler(fs, request, client_address, server)
......
......@@ -37,6 +37,7 @@ from fs.path import *
from fs.errors import *
from fs.local_functools import wraps
from fs.filelike import StringIO
from fs.utils import isdir
# Default host key used by BaseSFTPServer
......@@ -94,20 +95,35 @@ class SFTPServerInterface(paramiko.SFTPServerInterface):
path = path.decode(self.encoding)
stats = []
for entry in self.fs.listdir(path,absolute=True):
stats.append(self.stat(entry))
stat = self.stat(entry)
if not isinstance(stat, int):
stats.append(stat)
return stats
@report_sftp_errors
def stat(self, path):
if not isinstance(path, unicode):
path = path.decode(self.encoding)
info = self.fs.getinfo(path)
get = info.get
stat = paramiko.SFTPAttributes()
stat.filename = basename(path).encode(self.encoding)
stat.st_size = info.get("size")
stat.st_atime = time.mktime(info.get("accessed_time").timetuple())
stat.st_mtime = time.mktime(info.get("modified_time").timetuple())
if self.fs.isdir(path):
if 'st_atime' in info:
stat.st_atime = get('st_atime')
elif 'accessed_time' in info:
stat.st_atime = time.mktime(get("accessed_time").timetuple())
if 'st_mtime' in info:
stat.st_mtime = get('st_mtime')
else:
if 'modified_time' in info:
stat.st_mtime = time.mktime(get("modified_time").timetuple())
if isdir(self.fs, path, info):
stat.st_mode = 0777 | statinfo.S_IFDIR
else:
stat.st_mode = 0777 | statinfo.S_IFREG
......@@ -288,11 +304,11 @@ class BaseSFTPServer(sockserv.TCPServer,paramiko.ServerInterface):
return paramiko.AUTH_FAILED
def get_allowed_auths(self,username):
"""Return list of allowed auth modes.
"""Return string containing a comma separated list of allowed auth modes.
The available modes are "node", "password" and "publickey".
"""
return ("none",)
return "none"
# When called from the command-line, expose a TempFS for testing purposes
......
......@@ -153,6 +153,9 @@ class SFTPFS(FS):
self._agent_auth(connection, username)
if not connection.is_authenticated():
connection.auth_none('')
if not connection.is_authenticated():
connection.close()
raise RemoteConnectionError('no auth')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment