OverlordQ has asked for the wisdom of the Perl Monks concerning the following question:

Greetings monks. Currently I am trying to write a simple automated script using Net::FTP to upload a file. But, I have a few restrictions:

1) The script isn't for me, it's for somebody else.

2) They probably wont have perl installed on their computer (Windows Machine).

3) Sending the files to upload with the script.

So I was thinking I could write the script and use one of the 'compilers' (sorry I dont know the correct terminology), to convert the script to an executable. Now the question that's puzzling me is, is there any way to include the file I want to upload in some sort of __DATA__ section, or some other way to include the source file in with the script?

Title edit by tye

  • Comment on "Compile" Net::FTP upload script and use __DATA__ ?

Replies are listed 'Best First'.
Re: Net::FTP Question
by Thelonius (Priest) on May 16, 2003 at 21:03 UTC
    Although I haven't tried it, the documentation says that you can use a filehandle with the put method, so after you login, you should be able to
    $ftp->put(DATA, $remotefile);
    You might also be able to use IO::Scalar to send a string as if it were a file handle. Whether either of these would work with a given compliler, shrug!
      Using strict, it gives me:

      Bareword "DATA" not allowed while "strict subs" in use at ftp.pl line 12. Execution of ftp.pl aborted due to compilation errors.

      without strict, it gives me:

      Cannot open Local file DATA: No such file or directory at ftp.pl line 12

      Line 12 is: $ftp->put(DATA ,'index.html');

      Finally, skipping __DATA__ altogether and using IO::Scalar . . well nevermind . . that works wonderfully :)

      #!/usr/bin/perl use strict; use warnings; use IO::Scalar; use Net::FTP; my $ftp = Net::FTP->new("my.ftp.host", Debug => 0, Passive => 1); my $data = "<html><head><title>Foo</title></head><body>Bar</body></htm +l>"; my $SH = new IO::Scalar \$data; $ftp->login("username",'mypass'); $ftp->cwd("newpage"); $ftp->rename('file.html','file.old'); $ftp->put($SH ,'file.html');
Re: Net::FTP Question
by Util (Priest) on May 17, 2003 at 02:59 UTC

    Even if you can't directly do an FTP put from the <DATA> filehandle, you can write <DATA> to a real file, then put that file.

    # Completely untested :( use Net::FTP; use File::Temp qw(tempfile); my ($fh, $filename) = tempfile( DIR => '/' ); print $fh <DATA>; close $fh; ... set up your $ftp connection ... $ftp->put($filename); $ftp->quit; unlink $filename;