Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Uploading Unix text to IIS 5.0 Web Server with LWP?

by LameNerd (Hermit)
on Jun 12, 2003 at 18:44 UTC ( [id://265453]=perlquestion: print w/replies, xml ) Need Help??

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

Oh wise monks!

I have a LWP scripts that sends text files from a Unix system
to a IIS Web Server (I believe that is a MS Web Server.)
The admin at the remote site thinks that I have sent her a
big one line file. I guess I could modify my script to do something like ...
system ( 'unix2dos file2upLoad.unix > file2upload.dos' ); sendit ( 'file2upload.dos', $browser );
Where sendit looks like this:

sub sendit { my $local_filename = shift; my $browser = shift; my $remote_filename; my $local_filesize; my $text; my $request_number = 0; $local_filesize = -s $local_filename; $remote_filename = basename($local_filename); unless ($local_filesize > 0) { if ($debug_level > 0) { print "\nSendfile Error: $local_filename not found"; } return 0; } my $resp = $browser->post("$url/Upload", [ 'UploadFile' => [ $local_filename , $remote_filename , 'Content_Type' => "application/x-zip-compressed" ], 'Submit' => 'Send Request File' ], 'Content_Type' => 'form-data' ... );
But here's my question:

Shouldn't I change ...
'Content_Type' => "application/x-zip-compressed"
... to something like text/ascii?

Thanks

Replies are listed 'Best First'.
Re: Uploading Unix text to IIS 5.0 Web Server with LWP?
by theorbtwo (Prior) on Jun 12, 2003 at 19:25 UTC

    Yes, you should change the content-type to be text/plain. However, that won't fix your problem; you will (I think) need to convert the newlines. However, note that unix2dos is the equivlent of doing s/\cJ/\cM\cJ/sg in the string in question.

    Update: Fixed the first \cM to \cJ.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      Thanks for your reply. Hopefully you can help me with one question I have. How can I make my script work with web-servers that reside on different OS's? Is there a way for my client LWP script to determine what OS the web server is running on?

        No good way, no. What you can do is look at the Server: header that the web server sends you, and guess the newline convention from that. However, test if the server auto-converts the newlie convention when you fix your content-type.

        IMHO the best way to fix this is on the server side.

        Also, note the update in the grandparent node to this -- I had a \cM where I wanted a \cJ.


        Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://265453]
Approved by Ovid
Front-paged by virtualsue
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-29 02:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found