Advertisement
Guest User

Untitled

a guest
May 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import ftputil
  2. import sys
  3. import os
  4. import zipfile
  5. import codecs
  6. import json
  7. import xmltodict
  8. import csv
  9. import io
  10. import string
  11. import time
  12.  
  13. host_input = ftputil.FTPHost('ftp.zakupki.gov.ru', 'free', 'free')
  14. host_input_list = host_input.walk('/fcs_regions/Bajkonur_g')
  15. with codecs.open('D:\\Project\\task.txt', 'w') as input:
  16. for p,ds,fls in host_input_list:
  17. for fl in fls:
  18. path = p+'/'+fl
  19. path=path.strip()+'\n'
  20. input.write(path)
  21. host_input.close()
  22. input.close()
  23.  
  24. makelist()
  25. start_time = time.time()
  26. host = ftputil.FTPHost('ftp.zakupki.gov.ru', 'free', 'free')
  27. flag = 0
  28. while (flag == 0):
  29. k=0
  30. with codecs.open('D:\\Project\\task.txt') as files:
  31. for file in files:
  32. file = file.strip()
  33. if not os.path.exists('D:\\Project\\baik\\' + file.replace('/','')):
  34. curr_time = time.time()
  35. if (curr_time-start_time <= 600):
  36. try:
  37. host.download(file,'D:\\Project\\baik\\' + file.replace('/',''))
  38. print('file: \t' + file + '\t downloaded')
  39. except:
  40. k = k + 1
  41. print('\n\n\nФАЙЛ: \t' + file + '\t НЕ БЫЛ СКАЧАН \n\n\n')
  42. print('param k = %i\n\n\n', k)
  43. pass
  44. else:
  45. host.close()
  46. time.sleep(60)
  47. start_time=time.time()
  48. host = ftputil.FTPHost('ftp.zakupki.gov.ru', 'free', 'free')
  49. print('\n\n\n RECCONECT DONE \n\n\n')
  50. file = file.strip()
  51. try:
  52. host.download(file, 'D:\\Project\\baik\\' + file.replace('/', ''))
  53. print('file: \t' + file + '\t downloaded')
  54. except:
  55. k=k+1
  56. print('\n\n\nФАЙЛ: \t' + file + '\t НЕ БЫЛ СКАЧАН')
  57. print('param k = %i\n\n\n', k)
  58. pass
  59. if (k==0): flag = 1
  60. files.close()
  61. host.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement