There are times that, the sole purpose of FTP is to use the file, not to persist it to disk. Although you can ftp the file, store it to disk, and then open it, use it, after use, clean it up, but that sounds a little bit ugly to me (this made Net::FTP out of the picture). So in one of the project I am working on, I wrote this piece of code for myself. It is not a full implementation of FTP, but at the right size for my purpose. The original code is one function of an OO class, that's why you see all the $self->{} stuff, but for sure you can easily modify it to non-OO style. I post it here, thinking someone else might need a similar thing. (I only FTP ascii files, you might have to modify a little bit for binaries)
sub open_remote { my $self = shift; my $continue = 1; my $ftp = new IO::Socket::INET(Proto => "tcp", PeerAddr => $self->{HOST}, PeerPort => 21, Timeout => 60, Reuse => 1); if (!$ftp) { $continue = 0; print "Failed to new control socket\n" if ($self->{DEBUG}); } if ($continue) { my $response = <$ftp>; print $response if ($self->{DEBUG}); $continue = 0 if ($response !~ /^220/); } if ($continue) { print $ftp "USER $self->{USER}\r\n"; my $response = <$ftp>; print $response if ($self->{DEBUG}); $continue = 0 if ($response !~ /^331/); } if ($continue) { print $ftp "PASS $self->{PASSWD}\r\n"; my $response = <$ftp>; print $response if ($self->{DEBUG}); $continue = 0 if ($response !~ /^230/); } if ($continue) { print $ftp "CWD $self->{DIRECTORY}\r\n"; my $response = <$ftp>; print $response if ($self->{DEBUG}); $continue = 0 if ($response !~ /^250/); } my $data_l; my $data; if ($continue) { $data_l = new IO::Socket::INET(Proto => "tcp", LocalPort => $ftp->sockport(), Listen => 1, Timeout => 60, Reuse => 1); if (!$data_l) { $continue = 0; print "Failed to new data socket\n" if ($self->{DEBUG}); } } if ($continue) { print $ftp "RETR $self->{FILE}\r\n"; $data = $data_l->accept(); close($data_l); if (!$data) { print "failed to accept data connection\n" if ($self->{DEB +UG}); $continue = 0; } else { my $response = <$ftp>; print $response if ($self->{DEBUG}); @{$self->{DATA}} = <$data>; close($data); $response = <$ftp>; print $response if ($self->{DEBUG}); } } if ($ftp) { print $ftp "QUIT\r\n"; my $response = <$ftp>; print $response if ($self->{DEBUG}); close($ftp); } }

In reply to ftp, and store file in memory instead of persist to disk by pg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.