Python ftplib - uploading multiple files?

13,552

with the loop?

edit: in universal case uploading only files would look like this:

import os
for root, dirs, files in os.walk('path/to/local/dir'):
    for fname in files:
        full_fname = os.path.join(root, fname)
        ftp.storbinary('STOR remote/dir' + fname, open(full_fname, 'rb'))

Obviously, you need to look out for name collisions if you're just preserving file names like this.

Share:
13,552
Phil
Author by

Phil

Linux user, coding a little bit ;)

Updated on June 08, 2022

Comments

  • Phil
    Phil almost 2 years

    I've googled but I could only find how to upload one file... and I'm trying to upload all files from local directory to remote ftp directory. Any ideas how to achieve this?