http://qs321.pair.com?node_id=383725

prc_perl_c_c++_java has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I've been using perl for a while, but mostly i've been using it to move and create files around my desktop acording to w/e I need for the day. I recently started learning CGI. I understand the systme command things like telnet, but i don't understand, no matter how hard I try, the command FTP.

Can someone explain to me the syntax/use of FTP? thanks muchos

20040817 Janitored by Corion: Changed title from "FTP"

Replies are listed 'Best First'.
Re: FTP
by hardburn (Abbot) on Aug 17, 2004 at 16:36 UTC

    You're better off with a module like Net::FTP.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: FTP
by AcidHawk (Vicar) on Aug 17, 2004 at 19:12 UTC
    FTP ... stands for File Transfer Protocol. You have a server which has directories that you can read files from or copy file to (Depending on you access).

    By typing FTP at the shell (command line) you are starting a client that can "get" or "put" files on the server.

    If you are looking at doing this Client stuff from within a script hardburn is correct look at Net::FTP. (Example from the docs below)

    #You have to tell your script to use the module. use Net::FTP; #Establish a connection to the ftp server (in this case some.host +.name) $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; #provide the login information to the ftp server $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; #Change dir to /pub $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message; #copy the file from the ftp server to your local dir. $ftp->get("that.file") or die "get failed ", $ftp->message; #End your connection to the ftp server $ftp->quit;

    If you are looking to write a "kind of" server you need to look at Net::FTPServer although I have had no experience with this.

    -----
    Of all the things I've lost in my life, its my mind I miss the most.
Re: Help using FTP for CGI
by bart (Canon) on Aug 18, 2004 at 08:41 UTC
    See the online chapter from Lincoln Stein's book Network Programming with Perl, about Net::Telnet and Net::FTP: chapter 6.

    I must say I'm having a hard time imagining using FTP from inside a CGI script as a good idea. It seems like two separate worlds to me. And note that you can also use LWP (even LWP::Simple) to just download a file over FTP. Often that's a simpler solution. All you need to do is construct and use an ftp://... style URL.