Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ftplib - uploading multiple files?

Tags:

python

ftplib

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?

like image 564
Phil Avatar asked Dec 30 '22 20:12

Phil


1 Answers

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.

like image 184
SilentGhost Avatar answered Jan 20 '23 09:01

SilentGhost