{
    "content": [
        {
            "type": "text",
            "text": "# Net::FTP (perldoc)\n\n**Summary:** Net::FTP - FTP Client class\n\n**Synopsis:** use Net::FTP;\n$ftp = Net::FTP->new(\"some.host.name\", Debug => 0)\nor die \"Cannot connect to some.host.name: $@\";\n$ftp->login(\"anonymous\",'-anonymous@')\nor die \"Cannot login \", $ftp->message;\n$ftp->cwd(\"/pub\")\nor die \"Cannot change working directory \", $ftp->message;\n$ftp->get(\"that.file\")\nor die \"get failed \", $ftp->message;\n$ftp->quit;\n\n## Examples\n\n- `For an example of the use of Net::FTP see`\n- `<https://www.csh.rit.edu/~adam/Progs/>`\n- `\"autoftp\" is a program that can retrieve, send, or list files via the FTP protocol in a`\n- `non-interactive manner.`\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (16 lines)\n- **DESCRIPTION** (9 lines) — 6 subsections\n  - Overview (21 lines)\n  - Class Methods (62 lines)\n  - Object Methods (254 lines)\n  - Methods for the Adventurous (15 lines)\n  - The dataconn Class (3 lines)\n  - Unimplemented (24 lines)\n- **EXAMPLES** (6 lines)\n- **EXPORTS** (2 lines)\n- **KNOWN BUGS** (2 lines) — 1 subsections\n  - Reporting Bugs (8 lines)\n- **SEE ALSO** (2 lines) — 1 subsections\n  - ftp (3 lines)\n- **ACKNOWLEDGEMENTS** (7 lines)\n- **AUTHOR** (5 lines)\n- **COPYRIGHT** (4 lines)\n- **LICENCE** (4 lines)\n- **VERSION** (2 lines)\n- **DATE** (2 lines)\n- **HISTORY** (2 lines)\n\n## Full Content\n\n### NAME\n\nNet::FTP - FTP Client class\n\n### SYNOPSIS\n\nuse Net::FTP;\n\n$ftp = Net::FTP->new(\"some.host.name\", Debug => 0)\nor die \"Cannot connect to some.host.name: $@\";\n\n$ftp->login(\"anonymous\",'-anonymous@')\nor die \"Cannot login \", $ftp->message;\n\n$ftp->cwd(\"/pub\")\nor die \"Cannot change working directory \", $ftp->message;\n\n$ftp->get(\"that.file\")\nor die \"get failed \", $ftp->message;\n\n$ftp->quit;\n\n### DESCRIPTION\n\n\"Net::FTP\" is a class implementing a simple FTP client in Perl as described in RFC959. It\nprovides wrappers for the commonly used subset of the RFC959 commands. If IO::Socket::IP or\nIO::Socket::INET6 is installed it also provides support for IPv6 as defined in RFC2428. And with\nIO::Socket::SSL installed it provides support for implicit FTPS and explicit FTPS as defined in\nRFC4217.\n\nThe Net::FTP class is a subclass of Net::Cmd and (depending on avaibility) of IO::Socket::IP,\nIO::Socket::INET6 or IO::Socket::INET.\n\n#### Overview\n\nFTP stands for File Transfer Protocol. It is a way of transferring files between networked\nmachines. The protocol defines a client (whose commands are provided by this module) and a\nserver (not implemented in this module). Communication is always initiated by the client, and\nthe server responds with a message and a status code (and sometimes with data).\n\nThe FTP protocol allows files to be sent to or fetched from the server. Each transfer involves a\nlocal file (on the client) and a remote file (on the server). In this module, the same file name\nwill be used for both local and remote if only one is specified. This means that transferring\nremote file \"/path/to/file\" will try to put that file in \"/path/to/file\" locally, unless you\nspecify a local file name.\n\nThe protocol also defines several standard translations which the file can undergo during\ntransfer. These are ASCII, EBCDIC, binary, and byte. ASCII is the default type, and indicates\nthat the sender of files will translate the ends of lines to a standard representation which the\nreceiver will then translate back into their local representation. EBCDIC indicates the file\nbeing transferred is in EBCDIC format. Binary (also known as image) format sends the data as a\ncontiguous bit stream. Byte format transfers the data as bytes, the values of which remain the\nsame regardless of differences in byte size between the two machines (in theory - in practice\nyou should only use this if you really know what you're doing). This class does not support the\nEBCDIC or byte formats, and will default to binary instead if they are attempted.\n\n#### Class Methods\n\n\"new([$host][, %options])\"\nThis is the constructor for a new Net::FTP object. $host is the name of the remote host to\nwhich an FTP connection is required.\n\n$host is optional. If $host is not given then it may instead be passed as the \"Host\" option\ndescribed below.\n\n%options are passed in a hash like fashion, using key and value pairs. Possible options are:\n\nHost - FTP host to connect to. It may be a single scalar, as defined for the \"PeerAddr\"\noption in IO::Socket::INET, or a reference to an array with hosts to try in turn. The \"host\"\nmethod will return the value which was used to connect to the host.\n\nFirewall - The name of a machine which acts as an FTP firewall. This can be overridden by an\nenvironment variable \"FTPFIREWALL\". If specified, and the given host cannot be directly\nconnected to, then the connection is made to the firewall machine and the string @hostname\nis appended to the login identifier. This kind of setup is also referred to as an ftp proxy.\n\nFirewallType - The type of firewall running on the machine indicated by Firewall. This can\nbe overridden by an environment variable \"FTPFIREWALLTYPE\". For a list of permissible\ntypes, see the description of ftpfirewalltype in Net::Config.\n\nBlockSize - This is the block size that Net::FTP will use when doing transfers. (defaults to\n10240)\n\nPort - The port number to connect to on the remote machine for the FTP connection\n\nSSL - If the connection should be done from start with SSL, contrary to later upgrade with\n\"starttls\".\n\nSSL* - SSL arguments which will be applied when upgrading the control or data connection to\nSSL. You can use SSL arguments as documented in IO::Socket::SSL, but it will usually use the\nright arguments already.\n\nTimeout - Set a timeout value in seconds (defaults to 120)\n\nDebug - debug level (see the debug method in Net::Cmd)\n\nPassive - If set to a non-zero value then all data transfers will be done using passive\nmode. If set to zero then data transfers will be done using active mode. If the machine is\nconnected to the Internet directly, both passive and active mode should work equally well.\nBehind most firewall and NAT configurations passive mode has a better chance of working.\nHowever, in some rare firewall configurations, active mode actually works when passive mode\ndoesn't. Some really old FTP servers might not implement passive transfers. If not\nspecified, then the transfer mode is set by the environment variable \"FTPPASSIVE\" or if\nthat one is not set by the settings done by the libnetcfg utility. If none of these apply\nthen passive mode is used.\n\nHash - If given a reference to a file handle (e.g., \"\\*STDERR\"), print hash marks (#) on\nthat filehandle every 1024 bytes. This simply invokes the \"hash()\" method for you, so that\nhash marks are displayed for all transfers. You can, of course, call \"hash()\" explicitly\nwhenever you'd like.\n\nLocalAddr - Local address to use for all socket connections. This argument will be passed to\nthe super class, i.e. IO::Socket::INET or IO::Socket::IP.\n\nDomain - Domain to use, i.e. AFINET or AFINET6. This argument will be passed to the\nIO::Socket super class. This can be used to enforce IPv4 even with IO::Socket::IP which\nwould default to IPv6. Family is accepted as alternative name for Domain.\n\nIf the constructor fails undef will be returned and an error message will be in $@\n\n#### Object Methods\n\nUnless otherwise stated all methods return either a *true* or *false* value, with *true* meaning\nthat the operation was a success. When a method states that it returns a value, failure will be\nreturned as *undef* or an empty list.\n\n\"Net::FTP\" inherits from \"Net::Cmd\" so methods defined in \"Net::Cmd\" may be used to send\ncommands to the remote FTP server in addition to the methods documented here.\n\n\"login([$login[, $password[, $account]]])\"\nLog into the remote FTP server with the given login information. If no arguments are given\nthen the \"Net::FTP\" uses the \"Net::Netrc\" package to lookup the login information for the\nconnected host. If no information is found then a login of *anonymous* is used. If no\npassword is given and the login is *anonymous* then *anonymous@* will be used for password.\n\nIf the connection is via a firewall then the \"authorize\" method will be called with no\narguments.\n\n\"starttls()\"\nUpgrade existing plain connection to SSL. The SSL arguments have to be given in \"new\"\nalready because they are needed for data connections too.\n\n\"stoptls()\"\nDowngrade existing SSL connection back to plain. This is needed to work with some FTP\nhelpers at firewalls, which need to see the PORT and PASV commands and responses to\ndynamically open the necessary ports. In this case \"starttls\" is usually only done to\nprotect the authorization.\n\n\"prot($level)\"\nSet what type of data channel protection the client and server will be using. Only $levels\n\"C\" (clear) and \"P\" (private) are supported.\n\n\"host()\"\nReturns the value used by the constructor, and passed to the IO::Socket super class to\nconnect to the host.\n\n\"account($acct)\"\nSet a string identifying the user's account.\n\n\"authorize([$auth[, $resp]])\"\nThis is a protocol used by some firewall ftp proxies. It is used to authorise the user to\nsend data out. If both arguments are not specified then \"authorize\" uses \"Net::Netrc\" to do\na lookup.\n\n\"site($args)\"\nSend a SITE command to the remote server and wait for a response.\n\nReturns most significant digit of the response code.\n\n\"ascii()\"\nTransfer file in ASCII. CRLF translation will be done if required\n\n\"binary()\"\nTransfer file in binary mode. No transformation will be done.\n\nHint: If both server and client machines use the same line ending for text files, then it\nwill be faster to transfer all files in binary mode.\n\n\"type([$type])\"\nSet or get if files will be transferred in ASCII or binary mode.\n\n\"rename($oldname, $newname)\"\nRename a file on the remote FTP server from $oldname to $newname. This is done by sending\nthe RNFR and RNTO commands.\n\n\"delete($filename)\"\nSend a request to the server to delete $filename.\n\n\"cwd([$dir])\"\nAttempt to change directory to the directory given in $dir. If $dir is \"..\", the FTP \"CDUP\"\ncommand is used to attempt to move up one directory. If no directory is given then an\nattempt is made to change the directory to the root directory.\n\n\"cdup()\"\nChange directory to the parent of the current directory.\n\n\"passive([$passive])\"\nSet or get if data connections will be initiated in passive mode.\n\n\"pwd()\"\nReturns the full pathname of the current directory.\n\n\"restart($where)\"\nSet the byte offset at which to begin the next data transfer. Net::FTP simply records this\nvalue and uses it when during the next data transfer. For this reason this method will not\nreturn an error, but setting it may cause a subsequent data transfer to fail.\n\n\"rmdir($dir[, $recurse])\"\nRemove the directory with the name $dir. If $recurse is *true* then \"rmdir\" will attempt to\ndelete everything inside the directory.\n\n\"mkdir($dir[, $recurse])\"\nCreate a new directory with the name $dir. If $recurse is *true* then \"mkdir\" will attempt\nto create all the directories in the given path.\n\nReturns the full pathname to the new directory.\n\n\"alloc($size[, $recordsize])\"\nThe alloc command allows you to give the ftp server a hint about the size of the file about\nto be transferred using the ALLO ftp command. Some storage systems use this to make\nintelligent decisions about how to store the file. The $size argument represents the size of\nthe file in bytes. The $recordsize argument indicates a maximum record or page size for\nfiles sent with a record or page structure.\n\nThe size of the file will be determined, and sent to the server automatically for normal\nfiles so that this method need only be called if you are transferring data from a socket,\nnamed pipe, or other stream not associated with a normal file.\n\n\"ls([$dir])\"\nGet a directory listing of $dir, or the current directory.\n\nIn an array context, returns a list of lines returned from the server. In a scalar context,\nreturns a reference to a list.\n\n\"dir([$dir])\"\nGet a directory listing of $dir, or the current directory in long format.\n\nIn an array context, returns a list of lines returned from the server. In a scalar context,\nreturns a reference to a list.\n\n\"get($remotefile[, $localfile[, $where]])\"\nGet $remotefile from the server and store locally. $localfile may be a filename or a\nfilehandle. If not specified, the file will be stored in the current directory with the same\nleafname as the remote file.\n\nIf $where is given then the first $where bytes of the file will not be transferred, and the\nremaining bytes will be appended to the local file if it already exists.\n\nReturns $localfile, or the generated local file name if $localfile is not given. If an\nerror was encountered undef is returned.\n\n\"put($localfile[, $remotefile])\"\nPut a file on the remote server. $localfile may be a name or a filehandle. If $localfile\nis a filehandle then $remotefile must be specified. If $remotefile is not specified then\nthe file will be stored in the current directory with the same leafname as $localfile.\n\nReturns $remotefile, or the generated remote filename if $remotefile is not given.\n\nNOTE: If for some reason the transfer does not complete and an error is returned then the\ncontents that had been transferred will not be remove automatically.\n\n\"putunique($localfile[, $remotefile])\"\nSame as put but uses the \"STOU\" command.\n\nReturns the name of the file on the server.\n\n\"append($localfile[, $remotefile])\"\nSame as put but appends to the file on the remote server.\n\nReturns $remotefile, or the generated remote filename if $remotefile is not given.\n\n\"uniquename()\"\nReturns the name of the last file stored on the server using the \"STOU\" command.\n\n\"mdtm($file)\"\nReturns the *modification time* of the given file\n\n\"size($file)\"\nReturns the size in bytes for the given file as stored on the remote server.\n\nNOTE: The size reported is the size of the stored file on the remote server. If the file is\nsubsequently transferred from the server in ASCII mode and the remote server and local\nmachine have different ideas about \"End Of Line\" then the size of file on the local machine\nafter transfer may be different.\n\n\"supported($cmd)\"\nReturns TRUE if the remote server supports the given command.\n\n\"hash([$filehandleglobref[, $bytesperhashmark]])\"\nCalled without parameters, or with the first argument false, hash marks are suppressed. If\nthe first argument is true but not a reference to a file handle glob, then \\*STDERR is used.\nThe second argument is the number of bytes per hash mark printed, and defaults to 1024. In\nall cases the return value is a reference to an array of two: the filehandle glob reference\nand the bytes per hash mark.\n\n\"feature($name)\"\nDetermine if the server supports the specified feature. The return value is a list of lines\nthe server responded with to describe the options that it supports for the given feature. If\nthe feature is unsupported then the empty list is returned.\n\nif ($ftp->feature( 'MDTM' )) {\n# Do something\n}\n\nif (grep { /\\bTLS\\b/ } $ftp->feature('AUTH')) {\n# Server supports TLS\n}\n\nThe following methods can return different results depending on how they are called. If the user\nexplicitly calls either of the \"pasv\" or \"port\" methods then these methods will return a *true*\nor *false* value. If the user does not call either of these methods then the result will be a\nreference to a \"Net::FTP::dataconn\" based object.\n\n\"nlst([$dir])\"\nSend an \"NLST\" command to the server, with an optional parameter.\n\n\"list([$dir])\"\nSame as \"nlst\" but using the \"LIST\" command\n\n\"retr($file)\"\nBegin the retrieval of a file called $file from the remote server.\n\n\"stor($file)\"\nTell the server that you wish to store a file. $file is the name of the new file that should\nbe created.\n\n\"stou($file)\"\nSame as \"stor\" but using the \"STOU\" command. The name of the unique file which was created\non the server will be available via the \"uniquename\" method after the data connection has\nbeen closed.\n\n\"appe($file)\"\nTell the server that we want to append some data to the end of a file called $file. If this\nfile does not exist then create it.\n\nIf for some reason you want to have complete control over the data connection, this includes\ngenerating it and calling the \"response\" method when required, then the user can use these\nmethods to do so.\n\nHowever calling these methods only affects the use of the methods above that can return a data\nconnection. They have no effect on methods \"get\", \"put\", \"putunique\" and those that do not\nrequire data connections.\n\n\"port([$port])\"\n\"eprt([$port])\"\nSend a \"PORT\" (IPv4) or \"EPRT\" (IPv6) command to the server. If $port is specified then it\nis sent to the server. If not, then a listen socket is created and the correct information\nsent to the server.\n\n\"pasv()\"\n\"epsv()\"\nTell the server to go into passive mode (\"pasv\" for IPv4, \"epsv\" for IPv6). Returns the text\nthat represents the port on which the server is listening, this text is in a suitable form\nto send to another ftp server using the \"port\" or \"eprt\" method.\n\nThe following methods can be used to transfer files between two remote servers, providing that\nthese two servers can connect directly to each other.\n\n\"pasvxfer($srcfile, $destserver[, $destfile ])\"\nThis method will do a file transfer between two remote ftp servers. If $destfile is omitted\nthen the leaf name of $srcfile will be used.\n\n\"pasvxferunique($srcfile, $destserver[, $destfile ])\"\nLike \"pasvxfer\" but the file is stored on the remote server using the STOU command.\n\n\"pasvwait($nonpasvserver)\"\nThis method can be used to wait for a transfer to complete between a passive server and a\nnon-passive server. The method should be called on the passive server with the \"Net::FTP\"\nobject for the non-passive server passed as an argument.\n\n\"abort()\"\nAbort the current data transfer.\n\n\"quit()\"\nSend the QUIT command to the remote FTP server and close the socket connection.\n\n#### Methods for the Adventurous\n\n\"quot($cmd[, $args])\"\nSend a command, that Net::FTP does not directly support, to the remote server and wait for a\nresponse.\n\nReturns most significant digit of the response code.\n\nWARNING This call should only be used on commands that do not require data connections.\nMisuse of this method can hang the connection.\n\n\"caninet6()\"\nReturns whether we can use IPv6.\n\n\"canssl()\"\nReturns whether we can use SSL.\n\n#### The dataconn Class\n\nSome of the methods defined in \"Net::FTP\" return an object which will be derived from the\n\"Net::FTP::dataconn\" class. See Net::FTP::dataconn for more details.\n\n#### Unimplemented\n\nThe following RFC959 commands have not been implemented:\n\n\"SMNT\"\nMount a different file system structure without changing login or accounting information.\n\n\"HELP\"\nAsk the server for \"helpful information\" (that's what the RFC says) on the commands it\naccepts.\n\n\"MODE\"\nSpecifies transfer mode (stream, block or compressed) for file to be transferred.\n\n\"SYST\"\nRequest remote server system identification.\n\n\"STAT\"\nRequest remote server status.\n\n\"STRU\"\nSpecifies file structure for file to be transferred.\n\n\"REIN\"\nReinitialize the connection, flushing all I/O and account information.\n\n### EXAMPLES\n\nFor an example of the use of Net::FTP see\n\n<https://www.csh.rit.edu/~adam/Progs/>\n\"autoftp\" is a program that can retrieve, send, or list files via the FTP protocol in a\nnon-interactive manner.\n\n### EXPORTS\n\n*None*.\n\n### KNOWN BUGS\n\nSee <https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet>.\n\n#### Reporting Bugs\n\nWhen reporting bugs/problems please include as much information as possible. It may be difficult\nfor me to reproduce the problem as almost every setup is different.\n\nA small script which yields the problem will probably be of help. It would also be useful if\nthis script was run with the extra options \"Debug => 1\" passed to the constructor, and the\noutput sent with the bug report. If you cannot include a small script then please include a\nDebug trace from a run of your program which does yield the problem.\n\n### SEE ALSO\n\nNet::Netrc, Net::Cmd, IO::Socket::SSL;\n\n#### ftp\n\n<https://www.ietf.org/rfc/rfc959.txt>, <https://www.ietf.org/rfc/rfc2428.txt>,\n<https://www.ietf.org/rfc/rfc4217.txt>.\n\n### ACKNOWLEDGEMENTS\n\nHenry Gabryjelski <henryg@WPI.EDU <mailto:henryg@WPI.EDU>> - for the suggestion of creating\ndirectories recursively.\n\nNathan Torkington <gnat@frii.com <mailto:gnat@frii.com>> - for some input on the documentation.\n\nRoderick Schertler <roderick@gate.net <mailto:roderick@gate.net>> - for various inputs\n\n### AUTHOR\n\nGraham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.\n\nSteve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining libnet as of version\n1.2202.\n\n### COPYRIGHT\n\nCopyright (C) 1995-2004 Graham Barr. All rights reserved.\n\nCopyright (C) 2013-2017, 2020 Steve Hay. All rights reserved.\n\n### LICENCE\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself, i.e. under the terms of either the GNU General Public License or the Artistic\nLicense, as specified in the LICENCE file.\n\n### VERSION\n\nVersion 3.13\n\n### DATE\n\n23 Dec 2020\n\n### HISTORY\n\nSee the Changes file.\n\n"
        }
    ],
    "structuredContent": {
        "command": "Net::FTP",
        "section": "",
        "mode": "perldoc",
        "summary": "Net::FTP - FTP Client class",
        "synopsis": "use Net::FTP;\n$ftp = Net::FTP->new(\"some.host.name\", Debug => 0)\nor die \"Cannot connect to some.host.name: $@\";\n$ftp->login(\"anonymous\",'-anonymous@')\nor die \"Cannot login \", $ftp->message;\n$ftp->cwd(\"/pub\")\nor die \"Cannot change working directory \", $ftp->message;\n$ftp->get(\"that.file\")\nor die \"get failed \", $ftp->message;\n$ftp->quit;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "For an example of the use of Net::FTP see",
            "<https://www.csh.rit.edu/~adam/Progs/>",
            "\"autoftp\" is a program that can retrieve, send, or list files via the FTP protocol in a",
            "non-interactive manner."
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 9,
                "subsections": [
                    {
                        "name": "Overview",
                        "lines": 21
                    },
                    {
                        "name": "Class Methods",
                        "lines": 62
                    },
                    {
                        "name": "Object Methods",
                        "lines": 254
                    },
                    {
                        "name": "Methods for the Adventurous",
                        "lines": 15
                    },
                    {
                        "name": "The dataconn Class",
                        "lines": 3
                    },
                    {
                        "name": "Unimplemented",
                        "lines": 24
                    }
                ]
            },
            {
                "name": "EXAMPLES",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "EXPORTS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "KNOWN BUGS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Reporting Bugs",
                        "lines": 8
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": [
                    {
                        "name": "ftp",
                        "lines": 3
                    }
                ]
            },
            {
                "name": "ACKNOWLEDGEMENTS",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "LICENCE",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DATE",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "HISTORY",
                "lines": 2,
                "subsections": []
            }
        ]
    }
}