Skip to navigation
Download and upload a csv file with python3
07.03.17
#!/usr/bin/env python3 import os, sys, stat, sys import urllib.request import shutil import ftplib class Main(): def __init__(self): self.dowload_host = 'localhost' self.file_name = 'foo.csv' self.ftp_host = 'ftp.bar.com' self.ftp_user = 'foo' self.ftp_pass = 'barbarbar' def download(self): url = 'http://{}/code_trees?startwith={}&flat={}&format={}'.format(self.download_host,'KK','1','csv') response = urllib.request.urlopen(url) with urllib.request.urlopen(url) as response, open(self.file_name, 'wb') as out_file: shutil.copyfileobj(response, out_file) def ftp_upload(self): ftp = ftplib.FTP(self.ftp_host,self.ftp_user,self.ftp_pass) ftp.cwd('/synced_files/') xfile = open(self.file_name,'rb') ftp.storbinary('STOR ' + self.file_name,xfile) xfile.close() if __name__ == "__main__": a = Main() a.download() a.ftp_upload()
https://docs.python.org/3.6/library/ftplib.html
Reply
Anonymous
Information Epoch 1762590468
Data dominates.
Home
Notebook
Contact us