Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
upload folder in server ftp
#1
I have some folder and subfolder and files in my computer like this:
[Image: architectureDossier.png]
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:
[Image: dossierSurFtp.png]
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) 
Reply
#2
Do you have to do this with ftplib? I would try paramiko for this task.
Reply
#3
Hello
Thank you for your's answer, but i want to use ftplib.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cant access root environment folder from django folder using __init__.py Sanjish 0 733 Dec-25-2020, 05:56 AM
Last Post: Sanjish
  Upload big file on the server HTTP protocol Timych 1 1,138 May-15-2020, 07:12 AM
Last Post: snippsat
  How to Create a web server pointing to a folder using python pras120687 1 2,934 Nov-29-2016, 10:40 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020