MCPcopy Create free account
hub / github.com/ActiveState/code / main

Function main

recipes/Python/576777_Simple_FTP_Mirror/recipe-576777.py:346–452  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

344
345
346def main():
347 username = ''
348 password = ''
349 account = ''
350 try:
351 opts, args = getopt.getopt(sys.argv[1:], 'vqu:p:a:')
352 except getopt.GetoptError, msg:
353 log('%s\n%s' % (msg, __doc__), abort=True)
354 for opt, val in opts:
355 if opt == '-v': globals['verbose'] += 1
356 if opt == '-q': globals['verbose'] = 0
357 if opt == '-u': username = val
358 if opt == '-p': password = val
359 if opt == '-a': account = val
360
361 if not args:
362 log('No action given\n' + __doc__, abort=True)
363
364 action = args[0]
365 if action not in ('store', 'retrieve', 'remove', 'info'):
366 log('Unknown action: %s\n%s' % (action, __doc__), abort=True)
367
368 if len(args) == 1:
369 log('Missing hostname\n' + __doc__, abort=True)
370
371 args[1] = args[1].split(':')
372 host = args[1][0]
373 if len(args[1]) == 1:
374 port = 21
375 else:
376 port = int(args[1][1])
377
378 remotedir = '/'
379 if len(args) > 2:
380 remotedir = os.path.normpath(args[2])
381 if not remotedir.startswith('/'):
382 log('Invalid remotedir, must start with /', abort=True)
383
384 localdir = os.getcwd()
385 if len(args) > 3:
386 if action not in ('store', 'retrieve'):
387 log('Too many arguments\n%s' % __doc__, abort=True)
388 localdir = os.path.abspath(args[3])
389 if not os.path.isdir(localdir):
390 log('localdir does not exist: %s' % localdir, abort=True)
391
392 if len(args) > 4:
393 log('Too many arguments\n%s' % __doc__, abort=True)
394
395 if not username:
396 username = 'anonymous'
397 elif not password and globals['verbose']:
398 password = getpass.getpass('FTP Password: ')
399
400 ftp = ftplib.FTP()
401 if globals['verbose'] > 2:
402 ftp.set_debuglevel(globals['verbose']-2)
403 ftp.connect(host, port)

Callers 1

recipe-576777.pyFile · 0.70

Calls 15

localHandlerClass · 0.85
remoteHandlerClass · 0.85
mirrorFunction · 0.85
strfbytesFunction · 0.85
startswithMethod · 0.80
getcwdMethod · 0.80
isdirMethod · 0.80
loginMethod · 0.80
logFunction · 0.70
removeFunction · 0.70
infoFunction · 0.70
getoptMethod · 0.45

Tested by

no test coverage detected