Create missing directories in ftplib storbinary

后端 未结 6 848
傲寒
傲寒 2021-02-07 11:28

I was using pycurl to transfer files over ftp in python. I could create the missing directories automatically on my remote server using:

c.setopt(pycurl.FTP_CREA         


        
6条回答
  •  滥情空心
    2021-02-07 12:01

    I am using the following lines to resolve missing directory paths for FTP file copy

    import os
    ftps = FTP_TLS('ftps_server')
    ftps.connect()
    ftps.login()
    
    destination_dir_path = 'some/dir/path'          # directory path on FTP
    dir_path = ''
    for i in destination_dir_path.split('/'):
        dir_path = os.path.join(dir_path,i)
        if i not in ftps.nlst(os.path.dirname(dir_path)):
            ftps.mkd(dir_path)                      # create directory on the FTP
    ftps.storbinary(...)                            # store file using the binary mode
    

提交回复
热议问题