()
Test program.
    Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...

    -d dir
    -l list
    -p password
Test program.
    Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...
Test program . Usage : ftp [ - d ] [ - r [ file ]] host [ - l [ dir ]] [ - d [ dir ]] [ - p ] [ file ] ...
def test():
    '''Test program.
    Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...

    -d dir
    -l list
    -p password
    '''

    if len(sys.argv) < 2:
        print(test.__doc__)
        sys.exit(0)

    import netrc

    debugging = 0
    rcfile = None
    while sys.argv[1] == '-d':
        debugging = debugging+1
        del sys.argv[1]
    if sys.argv[1][:2] == '-r':
        # get name of alternate ~/.netrc file:
        rcfile = sys.argv[1][2:]
        del sys.argv[1]
    host = sys.argv[1]
    ftp = FTP(host)
    ftp.set_debuglevel(debugging)
    userid = passwd = acct = ''
    try:
        netrcobj = netrc.netrc(rcfile)
    except OSError:
        if rcfile is not None:
            sys.stderr.write("Could not open account file"
                             " -- using anonymous login.")
    else:
        try:
            userid, acct, passwd = netrcobj.authenticators(host)
        except KeyError:
            # no account for host
            sys.stderr.write(
                    "No account -- using anonymous login.")
    ftp.login(userid, passwd, acct)
    for file in sys.argv[2:]:
        if file[:2] == '-l':
            ftp.dir(file[2:])
        elif file[:2] == '-d':
            cmd = 'CWD'
            if file[2:]: cmd = cmd + ' ' + file[2:]
            resp = ftp.sendcmd(cmd)
        elif file == '-p':
            ftp.set_pasv(not ftp.passiveserver)
        else:
            ftp.retrbinary('RETR ' + file, \
                           sys.stdout.write, 1024)
    ftp.quit()
def test ( ) : if len ( sys . argv ) < 2 : print ( test . __doc__ ) sys . exit ( 0 ) import netrc debugging = 0 rcfile = None while sys . argv [ 1 ] == '-d' : debugging = debugging + 1 del sys . argv [ 1 ] if sys . argv [ 1 ] [ : 2 ] == '-r' : # get name of alternate ~/.netrc file: rcfile = sys . argv [ 1 ] [ 2 : ] del sys . argv [ 1 ] host = sys . argv [ 1 ] ftp = FTP ( host ) ftp . set_debuglevel ( debugging ) userid = passwd = acct = '' try : netrcobj = netrc . netrc ( rcfile ) except OSError : if rcfile is not None : sys . stderr . write ( "Could not open account file" " -- using anonymous login." ) else : try : userid , acct , passwd = netrcobj . authenticators ( host ) except KeyError : # no account for host sys . stderr . write ( "No account -- using anonymous login." ) ftp . login ( userid , passwd , acct ) for file in sys . argv [ 2 : ] : if file [ : 2 ] == '-l' : ftp . dir ( file [ 2 : ] ) elif file [ : 2 ] == '-d' : cmd = 'CWD' if file [ 2 : ] : cmd = cmd + ' ' + file [ 2 : ] resp = ftp . sendcmd ( cmd ) elif file == '-p' : ftp . set_pasv ( not ftp . passiveserver ) else : ftp . retrbinary ( 'RETR ' + file , sys . stdout . write , 1024 ) ftp . quit ( )