Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29320

Re: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'heavily': 0.04; 'subject:Python': 0.05; 'deprecated': 0.07; 'host,': 0.07; 'optparse': 0.07; 'username,': 0.07; 'subject:question': 0.08; 'python': 0.09; '__init__': 0.09; 'aix': 0.09; 'cmd': 0.09; 'dirname': 0.09; 'none.': 0.09; 'script,': 0.09; 'sep': 0.09; 'typeerror:': 0.09; 'def': 0.10; '--version': 0.16; '1:09': 0.16; 'argparse': 0.16; 'at,': 0.16; 'concatenate': 0.16; 'cwd': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'helps!': 0.16; 'isbn': 0.16; "o'reilly": 0.16; 'singleton': 0.16; 'subject: \n ': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'skip:" 40': 0.20; 'error.': 0.21; 'received:209.85.214.174': 0.21; "haven't": 0.23; 'command': 0.24; 'pass': 0.25; 'header:In- Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'options': 0.27; 'chris': 0.28; 'name?': 0.29; 'objects': 0.29; 'skip:_ 10': 0.29; 'probably': 0.29; 'error': 0.30; 'code': 0.31; 'server.': 0.32; 'url:python': 0.32; 'file': 0.32; 'skip:- 10': 0.32; 'getting': 0.33; 'docs': 0.33; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'tutorial': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'follows:': 0.35; 'options:': 0.35; 'open': 0.35; 'remote': 0.35; 'continue': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'but': 0.36; 'url:org': 0.36; 'subject:" ': 0.36; 'url:library': 0.36; 'skip:p 20': 0.36; 'being': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'object': 0.38; 'url:docs': 0.38; 'there,': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'notice': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'side': 0.61; 'provide': 0.62; 'worth': 0.63; 'information': 0.63; 'to,': 0.65; 'treat': 0.65; 'subject:skip:A 10': 0.75; 'favour': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=65i4FRdtoZaaVO5zGE5dFqWM9BujNL0iRCPYOPzkObM=; b=XHc+TTXr7kZNQWe/kA6/Rx5KFJMrOQ2xId6dQMLbJQ1KsHHpJalzg/yYzisJ51USt8 I7QVqbtBt/dgngH8An+NXzcgHB9KqTFrj9sf46IvlwQ84lYc6vIjerEIz7skD+8WUsi1 HgvuZp0TQOVtLlvUH8Y661xen5u4fldpsittTrOlkb/Xeq38PYwcd2TYB16LiU1nufY9 QPJleeMfSxpYk4UBGTym6Q2I71uMAqDaGwEG+Fmw7XPk+AGp7vXIG+RRKtwCW1sWA6RA LlbCpUgdtgVGO6x3OIkoAVf0wRpUz6KaNdD/5Qittc+Vc5Pv5b+m8uJd47fJseIgYhhK E8Dg==
MIME-Version 1.0
In-Reply-To <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com>
References <013b5f8b-d599-429b-9c07-3ff7306f4d5f@wz4g2000pbc.googlegroups.com>
Date Mon, 17 Sep 2012 01:41:52 +1000
Subject Re: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.796.1347810114.27098.python-list@python.org> (permalink)
Lines 57
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347810114 news.xs4all.nl 6898 [2001:888:2000:d::a6]:59993
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29320

Show key headers only | View raw


On Mon, Sep 17, 2012 at 1:09 AM, moonhkt <moonhkt@gmail.com> wrote:
> Hi All
>
> O'Reilly Book ISBN 978-986-6840-36-4.
>
> python --version
> Python 2.6.2 on AIX 5.3

Hi! Thanks for this, good information to open with.

> Using this python to get files in ftp server.
>
> I got below error. What is the error meaning and how to fix ?
>
> ftp_mirror.py
> Traceback (most recent call last):
>   File "/xx../shell/ftpmirror.py", line 80, in <module>
>     f = FTPSync(options.host, options.username, options.password,
> options.remote_dir, options.local_dir, opti
> ons.delete)
>   File "xx../shell/ftpmirror.py", line 17, in __init__
>     self.conn.cwd(ftp_base_dir)
>   File "/opt/freeware/lib/python2.6/ftplib.py", line 536, in cwd
>     cmd = 'CWD ' + dirname
> TypeError: cannot concatenate 'str' and 'NoneType' objects

NoneType is the type of the singleton object None. Why are you getting
None where you ought to be providing a directory name? Heavily trimmed
code follows:

>     def __init__(self, host, username, password, ftp_base_dir,
>                                 local_base_dir, delete=False):
>         self.conn.cwd(ftp_base_dir)
>     parser.add_option("-r", "--remote_dir", dest="remote_dir",
>          action='store', help="FTP remote starting directory")
>     f = FTPSync(options.host, options.username, options.password,
>             options.remote_dir, options.local_dir, options.delete)

If you don't pass -r/--remote_dir to your script, then (presumably - I
haven't actually used optparse so this is glarked from context)
options.remote_dir is being set to, or left at, None. A quick look at
the docs suggests that one solution is to add a default value to the
options:

http://docs.python.org/library/optparse.html#default-values

Alternatively, treat the options as mandatory, and provide them on the
command line.

Side point: When you go to the docs page there, you may notice that
optparse is deprecated in favour of argparse. May as well continue the
tutorial with what they recommend, but it's probably worth having a
look at argparse eventually.

Hope that helps!

Chris Angelico

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question moonhkt <moonhkt@gmail.com> - 2012-09-16 08:09 -0700
  Re: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question Joel Goldstick <joel.goldstick@gmail.com> - 2012-09-16 11:33 -0400
  Re: newbie question About O'Reilly "Python for Unix and Linux System Administration" ftp Mirror question Chris Angelico <rosuav@gmail.com> - 2012-09-17 01:41 +1000

csiph-web