Uploading file to a different web platform using ASP.NET/VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • brianinbox@gmail.com

    Uploading file to a different web platform using ASP.NET/VB.NET

    Hi,
    I've been trying to upload file using webclient.uploa dfile method
    from my IIS webserver to an Apache webserver without any success. On
    the Apache server (server that receives the incoming file) I have a
    simple php script, getFile.php to receive the file. The script look
    like this:

    <?php
    $uploadDir = '/var/www/Incoming/';
    $uploadFile = $uploadDir . $_FILES['userfile']['name'];
    print "<pre>";
    if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadFile))
    {
    print "File is valid, and was successfully uploaded. ";
    print "Here's some more debugging info:\n";
    print_r($_FILES );
    }
    else
    {
    print "Error receiving file:\n";
    print_r($_FILES );
    }
    print "</pre>";
    ?>

    I know this script work perfectly if I use a standard html with <input
    type="file"> method. However, file needs to be sent from an
    asp.net page instead of html. People on the newsgroup have been
    suggesting me to use webclient.uploa dfile method, however, I just could
    not get it to work.

    Perhaps there is something wrong with my php script or maybe there
    something else needs to be done to the webclient. If anybody has came
    across with the similar situation, can you show me how to do it both on
    the ASP.NET side and php side (or perl)


    Thanks
    Brian

  • recoil@community.nospam

    #2
    Re: Uploading file to a different web platform using ASP.NET/VB.NET

    This aspect of the question would best be suited in a php
    newsgroup/community. If you have related ASP.NET code using the
    UploadFile method then you can post that here.

    Comment

    • brianinbox@gmail.com

      #3
      Re: Uploading file to a different web platform using ASP.NET/VB.NET

      It might be a php and ASP.NET question and that's why I have it posted
      here.

      In my asp.net form I have

      wc as new webclient
      wc.uploadfile(" http://sample.com/getFile.php", "POST",
      "c:\temp\text.t xt") and I also tried
      wc.uploadfile(" http://sample.com/getFile.php", "c:\temp\text.t xt"),
      non of them returned any error, however the file never get uploaded.

      thanks
      Brian

      Comment

      • bruce barker

        #4
        Re: Uploading file to a different web platform using ASP.NET/VB.NET

        i haven't tested (use an network sniff or create a dump page), but suspect
        the name is not correct. the standard format is

        -----------------------------7d01ecf406a6
        Content-Disposition: form-data; name="myfile";
        filename="C:\In etpub\wwwroot\U pload\myFile.tx t"
        Content-Type: text/plain

        this is some test data

        -----------------------------7d01ecf406a6

        name equals the the name of the input file control in the html version

        <input type=file name="myfile>

        filename is the name of the file selected.

        as the webclient control does not allow to to specify the formdata name, it
        is either leaving it out or making one up. but your php script probably
        requies it.

        -- bruce (sqlwork.com)


        <brianinbox@gma il.com> wrote in message
        news:1110292889 .427226.301580@ z14g2000cwz.goo glegroups.com.. .
        | Hi,
        | I've been trying to upload file using webclient.uploa dfile method
        | from my IIS webserver to an Apache webserver without any success. On
        | the Apache server (server that receives the incoming file) I have a
        | simple php script, getFile.php to receive the file. The script look
        | like this:
        |
        | <?php
        | $uploadDir = '/var/www/Incoming/';
        | $uploadFile = $uploadDir . $_FILES['userfile']['name'];
        | print "<pre>";
        | if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadFile))
        | {
        | print "File is valid, and was successfully uploaded. ";
        | print "Here's some more debugging info:\n";
        | print_r($_FILES );
        | }
        | else
        | {
        | print "Error receiving file:\n";
        | print_r($_FILES );
        | }
        | print "</pre>";
        | ?>
        |
        | I know this script work perfectly if I use a standard html with <input
        | type="file"> method. However, file needs to be sent from an
        | asp.net page instead of html. People on the newsgroup have been
        | suggesting me to use webclient.uploa dfile method, however, I just could
        | not get it to work.
        |
        | Perhaps there is something wrong with my php script or maybe there
        | something else needs to be done to the webclient. If anybody has came
        | across with the similar situation, can you show me how to do it both on
        | the ASP.NET side and php side (or perl)
        |
        |
        | Thanks
        | Brian
        |


        Comment

        • Joerg Jooss

          #5
          Re: Uploading file to a different web platform using ASP.NET/VB.NET

          brianinbox@gmai l.com wrote:
          [color=blue]
          > Hi,
          > I've been trying to upload file using webclient.uploa dfile method
          > from my IIS webserver to an Apache webserver without any success. On
          > the Apache server (server that receives the incoming file) I have a
          > simple php script, getFile.php to receive the file. The script look
          > like this:
          >
          > <?php
          > $uploadDir = '/var/www/Incoming/';
          > $uploadFile = $uploadDir . $_FILES['userfile']['name'];
          > print "<pre>";
          > if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadFile))
          > {
          > print "File is valid, and was successfully uploaded. ";
          > print "Here's some more debugging info:\n";
          > print_r($_FILES );
          > }
          > else
          > {
          > print "Error receiving file:\n";
          > print_r($_FILES );
          > }
          > print "</pre>";
          > ?>
          >
          > I know this script work perfectly if I use a standard html with <input
          > type="file"> method. However, file needs to be sent from an
          > asp.net page instead of html. People on the newsgroup have been
          > suggesting me to use webclient.uploa dfile method, however, I just
          > could not get it to work.
          >
          > Perhaps there is something wrong with my php script or maybe there
          > something else needs to be done to the webclient. If anybody has came
          > across with the similar situation, can you show me how to do it both
          > on the ASP.NET side and php side (or perl)[/color]

          This is a bug in WebClient.Uploa dFile() that exists since .NET 1.0. It
          does not create a syntactically correct multipart/form-data request.
          You'll have to use WebRequest instead and build your own
          multipart/form-data request.

          Cheers,

          --

          mailto:news-reply@joergjoos s.de

          Comment

          Working...