Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: in memory files in 5.6.1

by WolliK (Acolyte)
on Apr 04, 2016 at 14:20 UTC ( #1159498=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: in memory files in 5.6.1
in thread in memory files in 5.6.1

Hi hanenkamp,
please do you have an idea to how handle these kind of "InMemoryfile" to put this on a local drive or to a webserver via HTTP::DAV of (S)FTP ?
The transfer programs allways want to have a filename instead a filehandle.

Regards
WolliK

Replies are listed 'Best First'.
Re^5: in memory files in 5.6.1
by afoken (Abbot) on Apr 04, 2016 at 20:31 UTC
    how handle these kind of "InMemoryfile" to put this on a local drive

    Well, just use a plain file instead!

    or to a webserver via HTTP::DAV of (S)FTP ? The transfer programs allways want to have a filename instead a filehandle.

    HTTP::DAV implements WebDAV, which is, as the name suggests, an extension to HTTP. HTTP does not know anything about files. So a sane DAV client should be able to upload arbitary data, not just files. And in fact, HTTP::DAV documents for the put method:

    One can upload/put a string by passing a reference to a scalar in the -local parameter.

    Of course, to access the scalar behind IO::Scalar, you need to pass a reference to a scalar to the constructor IO::Scalar->new(), see IO::Scalar. BTW: You would pass the same reference to HTTP::DAV's put() method.

    Net::SFTP implements open, read, write, close. No need to mess with in-memory files, but of course, you could write the scalar used to store the in-memory file using Net::SFTP's write method.

    Net::FTP accepts a file name or a file handle for put(), so you should be able to pass the IO::Scalar instance to put().

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Hi affoken,

      I've tried different ways, but none of them works. I've created a InMemoryFile withe two lines;
      foo_line_01\n
      foo_line_02\n

      Here are the output of my tests:

      Try to upload all the *.txt files from this directory:
      
      command: ..put( -local => "*.txt",   -url => "$url/$base_dir/$work_dir" )
      Reply..:   put *.txt succeeded
      
      Try to upload the InMemoryfile accessed via filehandler $fh:
      
      command: ..put( -local => "$fh",    -url => "$url/$base_dir/$work_dir" )
      Reply..:   put foo_Line_01
      foo_Line_02
       failed
      
      command: ..put( -local => \$fh,     -url => "$url/$base_dir/$work_dir" )
      Reply..:   put REF(0x274dc28) failed
      
      command: ..put( -local => $fhref,   -url => "$url/$base_dir/$work_dir" )
      Reply..:   put REF(0x274dc28) failed 
      
      command: ..put( -local => "\$fh",   -url => "$url/$base_dir/$work_dir" )
      Reply..:   put $fh failed
      
      command: ..put( -local => "\$fhref",-url => "$url/$base_dir/$work_dir" )
      Reply..:   put $fhref failed
      

      Any idea how to handle the -local parameter of the HTTP::DAV put request for an InMemoryfile linehandler?

      Regards
      WolliK
        command: ..put( -local => "$fh", -url => "$url/$base_dir/$work_dir" + ) Reply..: put foo_Line_01 foo_Line_02 failed command: ..put( -local => \$fh, -url => "$url/$base_dir/$work_dir" + ) Reply..: put REF(0x274dc28) failed command: ..put( -local => $fhref, -url => "$url/$base_dir/$work_dir" + ) Reply..: put REF(0x274dc28) failed command: ..put( -local => "\$fh", -url => "$url/$base_dir/$work_dir" + ) Reply..: put $fh failed command: ..put( -local => "\$fhref",-url => "$url/$base_dir/$work_dir" + ) Reply..: put $fhref failed
        Any idea how to handle the -local parameter of the HTTP::DAV put request for an InMemoryfile linehandler?

        Yes, sure. As I wrote:

        HTTP::DAV documents for the put method:

        One can upload/put a string by passing a reference to a scalar in the -local parameter.

        Of course, to access the scalar behind IO::Scalar, you need to pass a reference to a scalar to the constructor IO::Scalar->new(), see IO::Scalar. BTW: You would pass the same reference to HTTP::DAV's put() method.

        # (untested) my $storage=''; my $handle=IO::Scalar->new(\$storage); # use $handle to write to $storage here my $dav=HTTP::DAV->new(); # set up $dav here $dav->put( -local => \$storage, -url => 'http://www.example.com/davdemo/scalar.txt', ) or die "Put failed: ",join("\n",$dav->message(),$dav->errors());

        Stringifying references ("$fh", "\$fh", "\$fhref") can't work, put() needs a reference to a scalar to transfer the scalar's content. But stringifying creates a string like "SCALAR(0x1c34ac0)" that put() will treat as a file name.

        Also taking a reference to a reference won't work, you would at best transfer the stringified inner reference. Passing a reference to a handle won't work, as put expects a reference to a scalar (or a plain scalar containing a file name).


        Update:

        Your -url parameter for put() seems to be a directory. From a quick look at the sources of HTTP::DAV and HTTP::DAV::Resource,the -url parameter must be a filename if -local is a scalar reference. Else, HTTP::DAV will try to upload something that looks like a file to the DAV server to a resource that is a directory, not a file. Most likely, no sane DAV server will accept that. If you use put() with a local filename and a URL that points to a directory, HTTP::DAV will append the local filename (without directories) to the URL behind the scenes. This does not happen when -local is a reference to a scalar. A scalar reference simply does not have a filename that could be extracted and appended to the URL.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1159498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-02-16 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I use postfix dereferencing ...









    Results (95 votes). Check out past polls.

    Notices?