home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
pyhtmldoc
/
f
/
ftp_object
< prev
next >
Wrap
Text File
|
1996-11-14
|
7KB
|
123 lines
<TITLE>FTP Objects -- Python library reference</TITLE>
Prev: <A HREF="../f/ftplib" TYPE="Prev">ftplib</A>
Up: <A HREF="../f/ftplib" TYPE="Up">ftplib</A>
Top: <A HREF="../t/top" TYPE="Top">Top</A>
<H2>10.4.1. FTP Objects</H2>
FTP instances have the following methods:
<P>
<DL><DT><B>set_debuglevel</B> (<VAR>level</VAR>) -- Method on FTP object<DD>
Set the instance's debugging level. This controls the amount of
debugging output printed. The default, 0, produces no debugging
output. A value of 1 produces a moderate amount of debugging output,
generally a single line per request. A value of 2 or higher produces
the maximum amount of debugging output, logging each line sent and
received on the control connection.
</DL>
<DL><DT><B>connect</B> (<VAR>host</VAR>[, <VAR>port</VAR>]) -- Method on FTP object<DD>
Connect to the given host and port. The default port number is 21, as
specified by the FTP protocol specification. It is rarely needed to
specify a different port number. This function should be called only
once for each instance; it should not be called at all if a host was
given when the instance was created. All other methods can only be
used after a connection has been made.
</DL>
<DL><DT><B>getwelcome</B> () -- Method on FTP object<DD>
Return the welcome message sent by the server in reply to the initial
connection. (This message sometimes contains disclaimers or help
information that may be relevant to the user.)
</DL>
<DL><DT><B>login</B> ([<VAR>user</VAR>[, <VAR>passwd</VAR>[, <VAR>acct</VAR>]]]) -- Method on FTP object<DD>
Log in as the given <VAR>user</VAR>. The <VAR>passwd</VAR> and <VAR>acct</VAR>
parameters are optional and default to the empty string. If no
<VAR>user</VAR> is specified, it defaults to `<SAMP>anonymous</SAMP>'. If
<VAR>user</VAR> is <CODE>anonymous</CODE>, the default <VAR>passwd</VAR> is
`<SAMP><VAR>realuser</VAR>@<VAR>host</VAR></SAMP>' where <VAR>realuser</VAR> is the real user
name (glanced from the `<SAMP>LOGNAME</SAMP>' or `<SAMP>USER</SAMP>' environment
variable) and <VAR>host</VAR> is the hostname as returned by
<CODE>socket.gethostname()</CODE>. This function should be called only
once for each instance, after a connection has been established; it
should not be called at all if a host and user were given when the
instance was created. Most FTP commands are only allowed after the
client has logged in.
</DL>
<DL><DT><B>abort</B> () -- Method on FTP object<DD>
Abort a file transfer that is in progress. Using this does not always
work, but it's worth a try.
</DL>
<DL><DT><B>sendcmd</B> (<VAR>command</VAR>) -- Method on FTP object<DD>
Send a simple command string to the server and return the response
string.
</DL>
<DL><DT><B>voidcmd</B> (<VAR>command</VAR>) -- Method on FTP object<DD>
Send a simple command string to the server and handle the response.
Return nothing if a response code in the range 200--299 is received.
Raise an exception otherwise.
</DL>
<DL><DT><B>retrbinary</B> (<VAR>command</VAR>, <VAR>callback</VAR>, <VAR>maxblocksize</VAR>) -- Method on FTP object<DD>
Retrieve a file in binary transfer mode. <VAR>command</VAR> should be an
appropriate `<SAMP>RETR</SAMP>' command, i.e. <CODE>"RETR <VAR>filename</VAR>"</CODE>.
The <VAR>callback</VAR> function is called for each block of data received,
with a single string argument giving the data block.
The <VAR>maxblocksize</VAR> argument specifies the maximum block size
(which may not be the actual size of the data blocks passed to
<VAR>callback</VAR>).
</DL>
<DL><DT><B>retrlines</B> (<VAR>command</VAR>[, <VAR>callback</VAR>]) -- Method on FTP object<DD>
Retrieve a file or directory listing in ASCII transfer mode.
varcommand should be an appropriate `<SAMP>RETR</SAMP>' command (see
<CODE>retrbinary()</CODE> or a `<SAMP>LIST</SAMP>' command (usually just the string
<CODE>"LIST"</CODE>). The <VAR>callback</VAR> function is called for each line,
with the trailing CRLF stripped. The default <VAR>callback</VAR> prints
the line to <CODE>sys.stdout</CODE>.
</DL>
<DL><DT><B>storbinary</B> (<VAR>command</VAR>, <VAR>file</VAR>, <VAR>blocksize</VAR>) -- Method on FTP object<DD>
Store a file in binary transfer mode. <VAR>command</VAR> should be an
appropriate `<SAMP>STOR</SAMP>' command, i.e. <CODE>"STOR <VAR>filename</VAR>"</CODE>.
<VAR>file</VAR> is an open file object which is read until EOF using its
<CODE>read()</CODE> method in blocks of size <VAR>blocksize</VAR> to provide the
data to be stored.
</DL>
<DL><DT><B>storlines</B> (<VAR>command</VAR>, <VAR>file</VAR>) -- Method on FTP object<DD>
Store a file in ASCII transfer mode. <VAR>command</VAR> should be an
appropriate `<SAMP>STOR</SAMP>' command (see <CODE>storbinary()</CODE>). Lines are
read until EOF from the open file object <VAR>file</VAR> using its
<CODE>readline()</CODE> method to privide the data to be stored.
</DL>
<DL><DT><B>nlst</B> (<VAR>argument</VAR>[, @vardots]) -- Method on FTP object<DD>
Return a list of files as returned by the `<SAMP>NLST</SAMP>' command. The
optional varargument is a directory to list (default is the current
server directory). Multiple arguments can be used to pass
non-standard options to the `<SAMP>NLST</SAMP>' command.
</DL>
<DL><DT><B>dir</B> (<VAR>argument</VAR>[, @vardots]) -- Method on FTP object<DD>
Return a directory listing as returned by the `<SAMP>LIST</SAMP>' command, as
a list of lines. The optional varargument is a directory to list
(default is the current server directory). Multiple arguments can be
used to pass non-standard options to the `<SAMP>LIST</SAMP>' command. If the
last argument is a function, it is used as a <VAR>callback</VAR> function
as for <CODE>retrlines()</CODE>.
</DL>
<DL><DT><B>rename</B> (<VAR>fromname</VAR>, <VAR>toname</VAR>) -- Method on FTP object<DD>
Rename file <VAR>fromname</VAR> on the server to <VAR>toname</VAR>.
</DL>
<DL><DT><B>cwd</B> (<VAR>pathname</VAR>) -- Method on FTP object<DD>
Set the current directory on the server.
</DL>
<DL><DT><B>mkd</B> (<VAR>pathname</VAR>) -- Method on FTP object<DD>
Create a new directory on the server.
</DL>
<DL><DT><B>pwd</B> () -- Method on FTP object<DD>
Return the pathname of the current directory on the server.
</DL>
<DL><DT><B>quit</B> () -- Method on FTP object<DD>
Send a `<SAMP>QUIT</SAMP>' command to the server and close the connection.
This is the ``polite'' way to close a connection, but it may raise an
exception of the server reponds with an error to the <CODE>QUIT</CODE>
command.
</DL>
<DL><DT><B>close</B> () -- Method on FTP object<DD>
Close the connection unilaterally. This should not be applied to an
already closed connection (e.g. after a successful call to
<CODE>quit()</CODE>.
</DL>