1Net::FTP(3pm)          Perl Programmers Reference Guide          Net::FTP(3pm)
2
3
4

NAME

6       Net::FTP - FTP Client class
7

SYNOPSIS

9           use Net::FTP;
10
11           $ftp = Net::FTP->new("some.host.name", Debug => 0)
12             or die "Cannot connect to some.host.name: $@";
13
14           $ftp->login("anonymous",'-anonymous@')
15             or die "Cannot login ", $ftp->message;
16
17           $ftp->cwd("/pub")
18             or die "Cannot change working directory ", $ftp->message;
19
20           $ftp->get("that.file")
21             or die "get failed ", $ftp->message;
22
23           $ftp->quit;
24

DESCRIPTION

26       "Net::FTP" is a class implementing a simple FTP client in Perl as
27       described in RFC959.  It provides wrappers for a subset of the RFC959
28       commands.
29

OVERVIEW

31       FTP stands for File Transfer Protocol.  It is a way of transferring
32       files between networked machines.  The protocol defines a client (whose
33       commands are provided by this module) and a server (not implemented in
34       this module).  Communication is always initiated by the client, and the
35       server responds with a message and a status code (and sometimes with
36       data).
37
38       The FTP protocol allows files to be sent to or fetched from the server.
39       Each transfer involves a local file (on the client) and a remote file
40       (on the server).  In this module, the same file name will be used for
41       both local and remote if only one is specified.  This means that trans‐
42       ferring remote file "/path/to/file" will try to put that file in
43       "/path/to/file" locally, unless you specify a local file name.
44
45       The protocol also defines several standard translations which the file
46       can undergo during transfer.  These are ASCII, EBCDIC, binary, and
47       byte.  ASCII is the default type, and indicates that the sender of
48       files will translate the ends of lines to a standard representation
49       which the receiver will then translate back into their local represen‐
50       tation.  EBCDIC indicates the file being transferred is in EBCDIC for‐
51       mat.  Binary (also known as image) format sends the data as a contigu‐
52       ous bit stream.  Byte format transfers the data as bytes, the values of
53       which remain the same regardless of differences in byte size between
54       the two machines (in theory - in practice you should only use this if
55       you really know what you're doing).
56

CONSTRUCTOR

58       new ([ HOST ] [, OPTIONS ])
59           This is the constructor for a new Net::FTP object. "HOST" is the
60           name of the remote host to which an FTP connection is required.
61
62           "HOST" is optional. If "HOST" is not given then it may instead be
63           passed as the "Host" option described below.
64
65           "OPTIONS" are passed in a hash like fashion, using key and value
66           pairs.  Possible options are:
67
68           Host - FTP host to connect to. It may be a single scalar, as
69           defined for the "PeerAddr" option in IO::Socket::INET, or a refer‐
70           ence to an array with hosts to try in turn. The "host" method will
71           return the value which was used to connect to the host.
72
73           Firewall - The name of a machine which acts as an FTP firewall.
74           This can be overridden by an environment variable "FTP_FIREWALL".
75           If specified, and the given host cannot be directly connected to,
76           then the connection is made to the firewall machine and the string
77           @hostname is appended to the login identifier. This kind of setup
78           is also refered to as an ftp proxy.
79
80           FirewallType - The type of firewall running on the machine indi‐
81           cated by Firewall. This can be overridden by an environment vari‐
82           able "FTP_FIREWALL_TYPE". For a list of permissible types, see the
83           description of ftp_firewall_type in Net::Config.
84
85           BlockSize - This is the block size that Net::FTP will use when
86           doing transfers. (defaults to 10240)
87
88           Port - The port number to connect to on the remote machine for the
89           FTP connection
90
91           Timeout - Set a timeout value (defaults to 120)
92
93           Debug - debug level (see the debug method in Net::Cmd)
94
95           Passive - If set to a non-zero value then all data transfers will
96           be done using passive mode. This is not usually required except for
97           some dumb servers, and some firewall configurations. This can also
98           be set by the environment variable "FTP_PASSIVE".
99
100           Hash - If given a reference to a file handle (e.g., "\*STDERR"),
101           print hash marks (#) on that filehandle every 1024 bytes.  This
102           simply invokes the "hash()" method for you, so that hash marks are
103           displayed for all transfers.  You can, of course, call "hash()"
104           explicitly whenever you'd like.
105
106           LocalAddr - Local address to use for all socket connections, this
107           argument will be passed to IO::Socket::INET
108
109           If the constructor fails undef will be returned and an error mes‐
110           sage will be in $@
111

METHODS

113       Unless otherwise stated all methods return either a true or false
114       value, with true meaning that the operation was a success. When a
115       method states that it returns a value, failure will be returned as
116       undef or an empty list.
117
118       login ([LOGIN [,PASSWORD [, ACCOUNT] ] ])
119           Log into the remote FTP server with the given login information. If
120           no arguments are given then the "Net::FTP" uses the "Net::Netrc"
121           package to lookup the login information for the connected host.  If
122           no information is found then a login of anonymous is used.  If no
123           password is given and the login is anonymous then anonymous@ will
124           be used for password.
125
126           If the connection is via a firewall then the "authorize" method
127           will be called with no arguments.
128
129       authorize ( [AUTH [, RESP]])
130           This is a protocol used by some firewall ftp proxies. It is used to
131           authorise the user to send data out.  If both arguments are not
132           specified then "authorize" uses "Net::Netrc" to do a lookup.
133
134       site (ARGS)
135           Send a SITE command to the remote server and wait for a response.
136
137           Returns most significant digit of the response code.
138
139       ascii
140           Transfer file in ASCII. CRLF translation will be done if required
141
142       binary
143           Transfer file in binary mode. No transformation will be done.
144
145           Hint: If both server and client machines use the same line ending
146           for text files, then it will be faster to transfer all files in
147           binary mode.
148
149       rename ( OLDNAME, NEWNAME )
150           Rename a file on the remote FTP server from "OLDNAME" to "NEWNAME".
151           This is done by sending the RNFR and RNTO commands.
152
153       delete ( FILENAME )
154           Send a request to the server to delete "FILENAME".
155
156       cwd ( [ DIR ] )
157           Attempt to change directory to the directory given in $dir.  If
158           $dir is "..", the FTP "CDUP" command is used to attempt to move up
159           one directory. If no directory is given then an attempt is made to
160           change the directory to the root directory.
161
162       cdup ()
163           Change directory to the parent of the current directory.
164
165       pwd ()
166           Returns the full pathname of the current directory.
167
168       restart ( WHERE )
169           Set the byte offset at which to begin the next data transfer.
170           Net::FTP simply records this value and uses it when during the next
171           data transfer. For this reason this method will not return an
172           error, but setting it may cause a subsequent data transfer to fail.
173
174       rmdir ( DIR [, RECURSE ])
175           Remove the directory with the name "DIR". If "RECURSE" is true then
176           "rmdir" will attempt to delete everything inside the directory.
177
178       mkdir ( DIR [, RECURSE ])
179           Create a new directory with the name "DIR". If "RECURSE" is true
180           then "mkdir" will attempt to create all the directories in the
181           given path.
182
183           Returns the full pathname to the new directory.
184
185       alloc ( SIZE [, RECORD_SIZE] )
186           The alloc command allows you to give the ftp server a hint about
187           the size of the file about to be transfered using the ALLO ftp com‐
188           mand. Some storage systems use this to make intelligent decisions
189           about how to store the file.  The "SIZE" argument represents the
190           size of the file in bytes. The "RECORD_SIZE" argument indicates a
191           mazimum record or page size for files sent with a record or page
192           structure.
193
194           The size of the file will be determined, and sent to the server
195           automatically for normal files so that this method need only be
196           called if you are transfering data from a socket, named pipe, or
197           other stream not associated with a normal file.
198
199       ls ( [ DIR ] )
200           Get a directory listing of "DIR", or the current directory.
201
202           In an array context, returns a list of lines returned from the
203           server. In a scalar context, returns a reference to a list.
204
205       dir ( [ DIR ] )
206           Get a directory listing of "DIR", or the current directory in long
207           format.
208
209           In an array context, returns a list of lines returned from the
210           server. In a scalar context, returns a reference to a list.
211
212       get ( REMOTE_FILE [, LOCAL_FILE [, WHERE]] )
213           Get "REMOTE_FILE" from the server and store locally. "LOCAL_FILE"
214           may be a filename or a filehandle. If not specified, the file will
215           be stored in the current directory with the same leafname as the
216           remote file.
217
218           If "WHERE" is given then the first "WHERE" bytes of the file will
219           not be transfered, and the remaining bytes will be appended to the
220           local file if it already exists.
221
222           Returns "LOCAL_FILE", or the generated local file name if
223           "LOCAL_FILE" is not given. If an error was encountered undef is
224           returned.
225
226       put ( LOCAL_FILE [, REMOTE_FILE ] )
227           Put a file on the remote server. "LOCAL_FILE" may be a name or a
228           filehandle.  If "LOCAL_FILE" is a filehandle then "REMOTE_FILE"
229           must be specified. If "REMOTE_FILE" is not specified then the file
230           will be stored in the current directory with the same leafname as
231           "LOCAL_FILE".
232
233           Returns "REMOTE_FILE", or the generated remote filename if
234           "REMOTE_FILE" is not given.
235
236           NOTE: If for some reason the transfer does not complete and an
237           error is returned then the contents that had been transfered will
238           not be remove automatically.
239
240       put_unique ( LOCAL_FILE [, REMOTE_FILE ] )
241           Same as put but uses the "STOU" command.
242
243           Returns the name of the file on the server.
244
245       append ( LOCAL_FILE [, REMOTE_FILE ] )
246           Same as put but appends to the file on the remote server.
247
248           Returns "REMOTE_FILE", or the generated remote filename if
249           "REMOTE_FILE" is not given.
250
251       unique_name ()
252           Returns the name of the last file stored on the server using the
253           "STOU" command.
254
255       mdtm ( FILE )
256           Returns the modification time of the given file
257
258       size ( FILE )
259           Returns the size in bytes for the given file as stored on the
260           remote server.
261
262           NOTE: The size reported is the size of the stored file on the
263           remote server.  If the file is subsequently transfered from the
264           server in ASCII mode and the remote server and local machine have
265           different ideas about "End Of Line" then the size of file on the
266           local machine after transfer may be different.
267
268       supported ( CMD )
269           Returns TRUE if the remote server supports the given command.
270
271       hash ( [FILEHANDLE_GLOB_REF],[ BYTES_PER_HASH_MARK] )
272           Called without parameters, or with the first argument false, hash
273           marks are suppressed.  If the first argument is true but not a ref‐
274           erence to a file handle glob, then \*STDERR is used.  The second
275           argument is the number of bytes per hash mark printed, and defaults
276           to 1024.  In all cases the return value is a reference to an array
277           of two:  the filehandle glob reference and the bytes per hash mark.
278
279       The following methods can return different results depending on how
280       they are called. If the user explicitly calls either of the "pasv" or
281       "port" methods then these methods will return a true or false value. If
282       the user does not call either of these methods then the result will be
283       a reference to a "Net::FTP::dataconn" based object.
284
285       nlst ( [ DIR ] )
286           Send an "NLST" command to the server, with an optional parameter.
287
288       list ( [ DIR ] )
289           Same as "nlst" but using the "LIST" command
290
291       retr ( FILE )
292           Begin the retrieval of a file called "FILE" from the remote server.
293
294       stor ( FILE )
295           Tell the server that you wish to store a file. "FILE" is the name
296           of the new file that should be created.
297
298       stou ( FILE )
299           Same as "stor" but using the "STOU" command. The name of the unique
300           file which was created on the server will be available via the
301           "unique_name" method after the data connection has been closed.
302
303       appe ( FILE )
304           Tell the server that we want to append some data to the end of a
305           file called "FILE". If this file does not exist then create it.
306
307       If for some reason you want to have complete control over the data con‐
308       nection, this includes generating it and calling the "response" method
309       when required, then the user can use these methods to do so.
310
311       However calling these methods only affects the use of the methods above
312       that can return a data connection. They have no effect on methods
313       "get", "put", "put_unique" and those that do not require data connec‐
314       tions.
315
316       port ( [ PORT ] )
317           Send a "PORT" command to the server. If "PORT" is specified then it
318           is sent to the server. If not, then a listen socket is created and
319           the correct information sent to the server.
320
321       pasv ()
322           Tell the server to go into passive mode. Returns the text that rep‐
323           resents the port on which the server is listening, this text is in
324           a suitable form to sent to another ftp server using the "port"
325           method.
326
327       The following methods can be used to transfer files between two remote
328       servers, providing that these two servers can connect directly to each
329       other.
330
331       pasv_xfer ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
332           This method will do a file transfer between two remote ftp servers.
333           If "DEST_FILE" is omitted then the leaf name of "SRC_FILE" will be
334           used.
335
336       pasv_xfer_unique ( SRC_FILE, DEST_SERVER [, DEST_FILE ] )
337           Like "pasv_xfer" but the file is stored on the remote server using
338           the STOU command.
339
340       pasv_wait ( NON_PASV_SERVER )
341           This method can be used to wait for a transfer to complete between
342           a passive server and a non-passive server. The method should be
343           called on the passive server with the "Net::FTP" object for the
344           non-passive server passed as an argument.
345
346       abort ()
347           Abort the current data transfer.
348
349       quit ()
350           Send the QUIT command to the remote FTP server and close the socket
351           connection.
352
353       Methods for the adventurous
354
355       "Net::FTP" inherits from "Net::Cmd" so methods defined in "Net::Cmd"
356       may be used to send commands to the remote FTP server.
357
358       quot (CMD [,ARGS])
359           Send a command, that Net::FTP does not directly support, to the
360           remote server and wait for a response.
361
362           Returns most significant digit of the response code.
363
364           WARNING This call should only be used on commands that do not
365           require data connections. Misuse of this method can hang the con‐
366           nection.
367

THE dataconn CLASS

369       Some of the methods defined in "Net::FTP" return an object which will
370       be derived from this class.The dataconn class itself is derived from
371       the "IO::Socket::INET" class, so any normal IO operations can be per‐
372       formed.  However the following methods are defined in the dataconn
373       class and IO should be performed using these.
374
375       read ( BUFFER, SIZE [, TIMEOUT ] )
376           Read "SIZE" bytes of data from the server and place it into "BUF‐
377           FER", also performing any <CRLF> translation necessary. "TIMEOUT"
378           is optional, if not given, the timeout value from the command con‐
379           nection will be used.
380
381           Returns the number of bytes read before any <CRLF> translation.
382
383       write ( BUFFER, SIZE [, TIMEOUT ] )
384           Write "SIZE" bytes of data from "BUFFER" to the server, also per‐
385           forming any <CRLF> translation necessary. "TIMEOUT" is optional, if
386           not given, the timeout value from the command connection will be
387           used.
388
389           Returns the number of bytes written before any <CRLF> translation.
390
391       bytes_read ()
392           Returns the number of bytes read so far.
393
394       abort ()
395           Abort the current data transfer.
396
397       close ()
398           Close the data connection and get a response from the FTP server.
399           Returns true if the connection was closed successfully and the
400           first digit of the response from the server was a '2'.
401

UNIMPLEMENTED

403       The following RFC959 commands have not been implemented:
404
405       SMNT
406           Mount a different file system structure without changing login or
407           accounting information.
408
409       HELP
410           Ask the server for "helpful information" (that's what the RFC says)
411           on the commands it accepts.
412
413       MODE
414           Specifies transfer mode (stream, block or compressed) for file to
415           be transferred.
416
417       SYST
418           Request remote server system identification.
419
420       STAT
421           Request remote server status.
422
423       STRU
424           Specifies file structure for file to be transferred.
425
426       REIN
427           Reinitialize the connection, flushing all I/O and account informa‐
428           tion.
429

REPORTING BUGS

431       When reporting bugs/problems please include as much information as pos‐
432       sible.  It may be difficult for me to reproduce the problem as almost
433       every setup is different.
434
435       A small script which yields the problem will probably be of help. It
436       would also be useful if this script was run with the extra options
437       "Debug =" 1> passed to the constructor, and the output sent with the
438       bug report. If you cannot include a small script then please include a
439       Debug trace from a run of your program which does yield the problem.
440

AUTHOR

442       Graham Barr <gbarr@pobox.com>
443

SEE ALSO

445       Net::Netrc Net::Cmd
446
447       ftp(1), ftpd(8), RFC 959
448       http://www.cis.ohio-state.edu/htbin/rfc/rfc959.html
449

USE EXAMPLES

451       For an example of the use of Net::FTP see
452
453       http://www.csh.rit.edu/~adam/Progs/
454           "autoftp" is a program that can retrieve, send, or list files via
455           the FTP protocol in a non-interactive manner.
456

CREDITS

458       Henry Gabryjelski <henryg@WPI.EDU> - for the suggestion of creating
459       directories recursively.
460
461       Nathan Torkington <gnat@frii.com> - for some input on the documenta‐
462       tion.
463
464       Roderick Schertler <roderick@gate.net> - for various inputs
465
467       Copyright (c) 1995-2004 Graham Barr. All rights reserved.  This program
468       is free software; you can redistribute it and/or modify it under the
469       same terms as Perl itself.
470
471
472
473perl v5.8.8                       2001-09-21                     Net::FTP(3pm)
Impressum