MCPcopy Index your code
hub / github.com/python/cpython / test

Function test

Lib/ftplib.py:901–962  ·  view source on GitHub ↗

Test program. Usage: ftplib [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ... Options: -d increase debugging level -r[file] set alternate ~/.netrc file Commands: -l[dir] list directory -d[dir] change the current directory -p toggl

()

Source from the content-addressed store, hash-verified

899
900
901def test():
902 '''Test program.
903 Usage: ftplib [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...
904
905 Options:
906 -d increase debugging level
907 -r[file] set alternate ~/.netrc file
908
909 Commands:
910 -l[dir] list directory
911 -d[dir] change the current directory
912 -p toggle passive and active mode
913 file retrieve the file and write it to stdout
914 '''
915
916 if len(sys.argv) < 2:
917 print(test.__doc__)
918 sys.exit(0)
919
920 import netrc
921
922 debugging = 0
923 rcfile = None
924 while sys.argv[1] == '-d':
925 debugging = debugging+1
926 del sys.argv[1]
927 if sys.argv[1][:2] == '-r':
928 # get name of alternate ~/.netrc file:
929 rcfile = sys.argv[1][2:]
930 del sys.argv[1]
931 host = sys.argv[1]
932 ftp = FTP(host)
933 ftp.set_debuglevel(debugging)
934 userid = passwd = acct = ''
935 try:
936 netrcobj = netrc.netrc(rcfile)
937 except OSError:
938 if rcfile is not None:
939 print("Could not open account file -- using anonymous login.",
940 file=sys.stderr)
941 else:
942 try:
943 userid, acct, passwd = netrcobj.authenticators(host)
944 except (KeyError, TypeError):
945 # no account for host
946 print("No account -- using anonymous login.", file=sys.stderr)
947 ftp.login(userid, passwd, acct)
948 for file in sys.argv[2:]:
949 if file[:2] == '-l':
950 ftp.dir(file[2:])
951 elif file[:2] == '-d':
952 cmd = 'CWD'
953 if file[2:]: cmd = cmd + ' ' + file[2:]
954 ftp.sendcmd(cmd)
955 elif file == '-p':
956 ftp.set_pasv(not ftp.passiveserver)
957 else:
958 ftp.retrbinary('RETR ' + file, \

Callers 1

ftplib.pyFile · 0.70

Calls 11

set_debuglevelMethod · 0.95
loginMethod · 0.95
dirMethod · 0.95
sendcmdMethod · 0.95
set_pasvMethod · 0.95
retrbinaryMethod · 0.95
quitMethod · 0.95
FTPClass · 0.85
authenticatorsMethod · 0.80
exitMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…