[medusa] Changes to the FTP stuff for use by efs/ange-ftp.

Bill Tutt billtut@m...
Thu, 3 Feb 2000 12:59:45 -0800


Since I start and stop IIS all day for debugging the MSN Yellowpages, I
can't use IIS's FTP server from within XEmacs if I'm working remotely.

So, I figured, lets see how easy it would be to make Medusa handle the gig.
It turned out it wasn't that difficult.

Changes:
* Added support for XPWD since thats what the NT command line ftp client
sends.
* The long output now always includes the parent directory (".."), this is
mostly to make life easier in XEmacs efs based DirEd sessions. (no, DirEd
features via efs/ange-ftp haven't been tested, just simple navigation).
* NLST now requires the -l option to be specified in order to get long
output mode. All other ls options are ignored at the moment.
* Ignore the common "*"-only glob.

Notes:
* It should be fairly easy to extend whats going on here to add support for
more ls options.
* ".." shouldn't be listed if you're listing the root directory of the
filesystem.
* XEmacs was happy with the Unix long output that Medusa produced, I didn't
have to overload the system type response at all.
* I wasn't sure if cmd_list() should have identical processing as cmd_nlst()
so I didn't alter it.

Submitted for your pleasure/pain,
Bill


Index: filesys.py
===================================================================
RCS file: /usr/local/cvsroot/medusa/filesys.py,v
retrieving revision 1.9
diff -u -r1.9 filesys.py
--- filesys.py	1998/06/22 05:36:05	1.9
+++ filesys.py	2000/02/03 13:48:11
@@ -132,6 +132,9 @@
return self.cwd ('..')

def listdir (self, path, long=0):
+	# Cheesy yanking of the all inclusive glob.
+	if path == "*":
+	path = ""
p = self.translate (path)
# I think we should glob, but limit it to the current
# directory only.
@@ -139,6 +142,10 @@
if not long:
return list_producer (ld, 0, None)
else:
+	# add ".." if we're doing the long printout.
+	# This really should only happen when -a or -A is
used
+	# but, the option logic doesn't make its way down
here.
+	ld = [".."] + ld
old_dir = os.getcwd()
try:
os.chdir (p)
Index: ftp_server.py
===================================================================
RCS file: /usr/local/cvsroot/medusa/ftp_server.py,v
retrieving revision 2.39
diff -u -r2.39 ftp_server.py
--- ftp_server.py	1999/11/19 09:25:34	2.39
+++ ftp_server.py	2000/02/03 13:48:11
@@ -32,6 +32,9 @@
import string
import sys
import time
+import StringIO
+import shlex
+import getopt

# TODO: implement a directory listing cache. On very-high-load
# servers this could save a lot of disk abuse, and possibly the
@@ -198,19 +201,22 @@

def get_dir_list (self, line, long=0):
# we need to scan the command line for arguments to
'/bin/ls'...
-	args = line[1:]
-	path_args = []
-	for arg in args:
-	if arg[0] != '-':
-	path_args.append (arg)
-	else:
-	# ignore arguments
-	pass
-	if len(path_args) < 1:
-	dir = '.'
+	# and strip them away since we currently don't make use of
them.
+	# (except for triggering long mode...)
+	if len(line) > 1:
+	args = line[1]
+	# convert args into a list of arguments.
+	args = ConvertArgsStringToArgsList (args)
+	# Cool, now we can run this thing through getopt.
+	optlist, args = getopt.getopt (args,
"abcdfgiklmnpqrstuxABCFGLNQRSUX")
+	for opt, optValue in optlist:
+	if opt == "-l":
+	long = 1
+	args = [args[0]]
else:
-	dir = path_args[0]
-	return self.listdir (dir, long)
+	args = ["."]
+	return self.listdir (args, long)
+

# --------------------------------------------------
# authorization methods
@@ -378,12 +384,8 @@

def cmd_nlst (self, line):
'give name list of files in directory'
-	# ncftp adds the -FC argument for the user-visible 'nlist'
-	# command. We could try to emulate ls flags, but not just
yet.
-	if '-FC' in line:
-	line.remove ('-FC')
try:
-	dir_list_producer = self.get_dir_list (line, 0)
+	dir_list_producer = self.get_dir_list (line)
except os.error, why:
self.respond ('550 Could not list directory: %s' %
repr(why))
return
@@ -433,6 +435,9 @@
self.filesystem.current_directory()
)
)
+	
+	def cmd_xpwd (self, line):
+	self.cmd_pwd(line)

# modification time
# example output:
@@ -1110,7 +1115,7 @@
'xcup':	'change to parent of current working directory
(deprecated)',
'xcwd':	'change working directory (deprecated)',
'xmkd':	'make a directory (deprecated)',
#!
-	'xpwd':	'print the current working directory (deprecated)',
+	'xpwd':	'print the current working directory (deprecated)', #*
'xrmd':	'remove a directory (deprecated)',
#!
}

@@ -1121,3 +1126,18 @@

def print_vm():
print 'vm: %8dk' % (get_vm_size()/1024)
+
+# Convert a string containing an argument list
+# to the actual list of arguments.
+def ConvertArgStringToArgList(s):
+	# All praise shlex!
+	lex = shlex.shlex(StringIO.StringIO(s))
+	# Add '-' to the set of word characters so that '-''s group
+	# to the flags
+	lex.wordchars = lex.wordchars + '-'
+	lArgs = []
+	token = lex.get_token()
+	while token != '':
+	lArgs.append(token)
+	token = lex.get_token()
+	return lArgs