upload folder in server ftp - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: upload folder in server ftp (/thread-13829.html) |
upload folder in server ftp - falloff - Nov-02-2018 I have some folder and subfolder and files in my computer like this: and i want to upload this folders and files in my serveur ftp. I have a code but is wrong because my folder go to the server ftp like that: here is the code import ftplib import os server = 'localhost' username = 'generic_user' password = 'password' myFTP = ftplib.FTP(server, username, password) myPath = r'/Users/olivier/Documents/essai' def uploadThis(path): files = os.listdir(path) os.chdir(path) for f in files: if os.path.isfile(f): fh = open(f, 'rb') myFTP.storbinary('STOR %s' % f, fh) fh.close() elif os.path.isdir(f): myFTP.mkd(f) myFTP.cwd(f) uploadThis(f) myFTP.cwd('..') os.chdir('..') uploadThis(myPath) RE: upload folder in server ftp - Gribouillis - Nov-02-2018 Do you have to do this with ftplib? I would try paramiko for this task. RE: upload folder in server ftp - falloff - Nov-02-2018 Hello Thank you for your's answer, but i want to use ftplib. RE: upload folder in server ftp - Gribouillis - Nov-02-2018 There is this module pyftp in github. Its code is quite short and it has a method put_d() to upload a whole folder. Examining the code should give you the solution.
|