473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ftputil.py

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

May 24 '06 #1
2 2265
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/

May 24 '06 #2
Thanks!

Sheldon

May 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: geon | last post by:
Hi, When I try to upload many files I get such a error message: Traceback (most recent call last): File "I:\Python\my_py\wwwzaci\xcopy_ftp.py", line 51, in ? except: x=host.upload(zdroj,...
1
by: s99999999s2003 | last post by:
hi i am currently using the FTP wrapper from http://cheeseshop.python.org/pypi/ftputil/2.0.3 The documentation states "In the current implementation, this doesn't construct "intermediate"...
0
by: veki | last post by:
HI,ALL I am new ftputil user and I need help about something: my prog: >>> import tkFileDialog >>> import ftputil >>> name=tkFileDialog.askopenfile() >>>ftp=ftputil.FTPHost() #Please when you...
2
by: vedran_dekovic | last post by:
Hi, Again I need help about tkinter listbox. example: In listbox must write (imaginary file in server): vedran@vedran.byethost12.com vedran.byethost12.com 3506 Jun 25 14:40 file.gif']
0
by: vedran_dekovic | last post by:
Hi, For people who using ftputil: Have ftputil any protection(SSL......) or any other protection?????
1
by: Croteam | last post by:
Hello, I have one problem about ftputil file upload.Here is my short example: from ftputil import FTPHost import tkFileDialog import os from Tkinter import Tk ...
0
by: Croteam | last post by:
Hello, I trying to make a ftp software,and I have one question about it. After user connect to his ftp account, command e.g. ftp._dir('') must insert folder and files (from that ftp host) in...
1
by: Croteam | last post by:
Hello, I trying to make ftputil client that uses ssl security.First I was try to make that with M2Crypto,but when I use it, I get the error: Traceback (most recent call last): File...
2
by: IanC | last post by:
Hi, Does anyone know of a function or script to upload an entire subdirectory tree from a local file space to an FTP server? The Python distribution comes with "ftpmirror.py", which performs...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.