FAQ
Hi Everyone,

I recently installed a module called ftputil and I am trying to
understand how it works.
I created a simple program to download about 1500 files from my ftp and
the program looks like this:

**************************************************************************
#! /usr/bin/env python
#-*- coding: UTF-8 -*-

def ftp_fetch(newdir):
import sys
import ftputil
# download some files from the login directory
host = ftputil.FTPHost('ftp.xxxx.xx', 'xxxxxx', 'xxxxxxx')
names = host.listdir(host.curdir)
print "There are %d files on the FTP server to be downloaded" %
len(names)
for name in names:
if host.path.isfile(name):
host.download(name, name, 'b') # remote, local, binary
mode
#make a new directory and copy a remote file into it
host.mkdir('newdir')
source = host.file('index.html', 'r') # file-like object
target = host.file('newdir/index.html', 'w') # file-like object
host.copyfileobj(source, target) # similar to shutil.copyfileobj
source.close()
target.close()

return 0

#--------------------------------
if __name__== "__main__":
import os
import sys
newdir = os.getcwd()
print "Downloading files from FTP into directory: %s" % newdir
#sys.exit(0)
stat = ftp_fetch(newdir)
**********************************************************************************

Now I also need to write another function to upload files and I
haven't the faintest idea yet.
Here is the part of the program that I need explained:

host.download(name, name, 'b') # remote, local, binary mode
source = host.file('index.html', 'r') # file-like object
target = host.file('newdir/index.html', 'w') # file-like object
host.copyfileobj(source, target) # similar to shutil.copyfileobj

Any help would be greatly appreciated!

Sincerely,
Sheldon

Search Discussions

  • Miki at May 24, 2006 at 8:07 am
    Hello Sheldon,
    Here is the part of the program that I need explained:

    host.download(name, name, 'b') # remote, local, binary mode
    Download file called "name" from host to a local file in the same name,
    use binary mode.
    source = host.file('index.html', 'r') # file-like object
    Open a file (like built-in "open") on remote site in read mode
    target = host.file('newdir/index.html', 'w') # file-like object
    Open a file (like built-in "open") on remote site in write mode
    host.copyfileobj(source, target) # similar to shutil.copyfileobj
    Copy 1'st file to the second.

    HTH,
    Miki
    http://pythonwise.blogspot.com/
  • Sheldon at May 24, 2006 at 10:32 am
    Thanks!

    Sheldon

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 24, '06 at 7:14a
activeMay 24, '06 at 10:32a
posts3
users2
websitepython.org

2 users in discussion

Sheldon: 2 posts Miki: 1 post

People

Translate

site design / logo © 2022 Grokbase