MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / test

Function test

tools/python-3.11.9-amd64/Lib/ftplib.py:923–984  ·  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

()

Source from the content-addressed store, hash-verified

921
922
923def test():
924 '''Test program.
925 Usage: ftplib [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...
926
927 Options:
928 -d increase debugging level
929 -r[file] set alternate ~/.netrc file
930
931 Commands:
932 -l[dir] list directory
933 -d[dir] change the current directory
934 -p toggle passive and active mode
935 file retrieve the file and write it to stdout
936 '''
937
938 if len(sys.argv) < 2:
939 print(test.__doc__)
940 sys.exit(0)
941
942 import netrc
943
944 debugging = 0
945 rcfile = None
946 while sys.argv[1] == '-d':
947 debugging = debugging+1
948 del sys.argv[1]
949 if sys.argv[1][:2] == '-r':
950 # get name of alternate ~/.netrc file:
951 rcfile = sys.argv[1][2:]
952 del sys.argv[1]
953 host = sys.argv[1]
954 ftp = FTP(host)
955 ftp.set_debuglevel(debugging)
956 userid = passwd = acct = ''
957 try:
958 netrcobj = netrc.netrc(rcfile)
959 except OSError:
960 if rcfile is not None:
961 print("Could not open account file -- using anonymous login.",
962 file=sys.stderr)
963 else:
964 try:
965 userid, acct, passwd = netrcobj.authenticators(host)
966 except (KeyError, TypeError):
967 # no account for host
968 print("No account -- using anonymous login.", file=sys.stderr)
969 ftp.login(userid, passwd, acct)
970 for file in sys.argv[2:]:
971 if file[:2] == '-l':
972 ftp.dir(file[2:])
973 elif file[:2] == '-d':
974 cmd = 'CWD'
975 if file[2:]: cmd = cmd + ' ' + file[2:]
976 resp = ftp.sendcmd(cmd)
977 elif file == '-p':
978 ftp.set_pasv(not ftp.passiveserver)
979 else:
980 ftp.retrbinary('RETR ' + file, \

Callers 1

ftplib.pyFile · 0.70

Calls 12

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
printFunction · 0.50
exitMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected