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 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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
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"...
|
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...
|
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']
|
by: vedran_dekovic |
last post by:
Hi,
For people who using ftputil:
Have ftputil any protection(SSL......) or any other protection?????
|
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
...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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,...
|
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...
| |