[ftputil] FTPUTIL PROBLEM

Stefan Schwarzer sschwarzer at sschwarzer.net
Mon Aug 7 15:20:03 CEST 2006


Hi :)

(Your mail arrived badly formatted; the line breaks in your
original code and the traceback were missing. It seems that your
mail client is broken; you may speak to the provider of the web
mail service you use. I reformatted your text.)

> 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 want try this prog use your ftp server
> >>> nesto1=name.name
> >>> ftp.upload(nesto1,nesto1,'b')
>
> ERROR IS:
> Traceback (most recent call last):
> File &quot;<pyshell#6>&quot;, line 1, in -toplevel-
>   ftp.upload(nesto1,nesto1,'b')
> File &quot;C:\Python24\lib\ftputil.py&quot;, line 463, in upload
>   self.__copy_file(source, target, mode, open, self.file)
> File &quot;C:\Python24\lib\ftputil.py&quot;, line 452, in__copy_file
>   target = target_open(target, target_mode)
> File &quot;C:\Python24\lib\ftputil.py&quot;, line 282, in file
>   raise ftp_error.FTPIOError(&quot;directory '%s' is notaccessible&quot; %FTPIOError: directory '/C:/Python24' is not accessible

You try to use exactly the same file name (including path, that
including drive letter) for the source and the target file. Since
the directory "/C:/Python24" probably isn't on the server, ftputil
complains that the directory isn't accessible. The error message
is correct, but it should maybe tell that the directory might not
exist at all.

Assuming you want to select a local file and upload it to the
current directory on the server, you should replace your code

  ftp.upload(nesto1,nesto1,'b')

with

  import os
  ...
  ftp.upload(nesto1, os.path.basename(nesto1), 'b')

On using os.path.basename vs. ftp.path.basename: The argument
string is the name, including path, of a local file, so the
function for a local file system (i. e. os.path.basename) should
be used to remove the drive letter and the directory part.

Does this help? :-)

Stefan



More information about the ftputil mailing list