tags:

views:

919

answers:

2

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?

+3  A: 

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.storebinary('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.

SilentGhost
It's script that would upload website to host... so lets say i have website in some directory on my local hard drive and i want to upload its contents but NOT with directory, only files so my website after being uploaded will be accessible from myaddress.com instead of myaddress.com/somedirectory
Phil
A: 

Create a FTP batch file (with a list of files that you need to transfer). Use python to execute ftp.exe with the "-s" option and pass in the list of files.

This is kludgy but apparently the FTPlib does not have accept multiple files in its STOR command.

Here is a sample ftp batch file.

*

OPEN inetxxx 
myuser mypasswd 
binary 
prompt off 
cd ~/my_reg/cronjobs/k_load/incoming 
mput *.csv 
bye
  • If the above contents were in a file called "abc.ftp" - then my ftp command would be

    ftp -s abc.ftp

Hope that helps.

blispr
...I'm on Linux ;)
Phil
I implied an myftp.ftp file as a 'batch' file and not an MSDOS specific ".bat" file.This file will contain a list of ftp commands (and not OS-specific commands).For example , here's one of mine -OPEN inetxxxmyusermypasswdbinaryprompt offcd ~/my_reg/cronjobs/k_load/incomingmput *.csvbye
blispr
this way is not portable, and why use another ftp client when Python has its own. For multiple, do it the way like SilentGhost did.
ghostdog74