upload ftp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alain Dhaene

    upload ftp

    HI,

    I have follow problem. I want upload a file to a map on a ftp server.

    I make a connection to a ftp server. That's ok.
    Then I make a directory

    ftp_chdir($conn _id,"/public_html/info"); //ok

    if(ftp_mkdir($c onn_id,"uploads ")) print ("File is created!"); //ok

    ftp_chdir($conn _id,"/public_html/info/uploads"); //ok ?????



    $source_file = $_FILES['userfile']['name']; //ok exist (is a file from
    the local drive

    $destination ="/public_html/info/uploads"; //I think that's the map I make

    $upload = ftp_fput($conn_ id, $source_file , $destination_fi le, FTP_BINARY);

    print $upload gives false

    The error in the browser :

    File is created!
    /public_html/info/uploads

    Warning: ftp_fput() expects parameter 3 to be resource, string given in
    /home/school/public_html/result.php on line 37
    FTP upload has failed!



    What's wrong?

    thxt,



    Alain



  • Rahul Anand

    #2
    Re: upload ftp

    "Alain Dhaene" <alain.dhaene@w orldonline.be> wrote in message news:<bvbnl8$cs a$1@news.worldo nline.be>...[color=blue]
    > HI,
    >
    > I have follow problem. I want upload a file to a map on a ftp server.
    >
    > I make a connection to a ftp server. That's ok.
    > Then I make a directory
    >
    > ftp_chdir($conn _id,"/public_html/info"); //ok
    >
    > if(ftp_mkdir($c onn_id,"uploads ")) print ("File is created!"); //ok
    >
    > ftp_chdir($conn _id,"/public_html/info/uploads"); //ok ?????
    >
    >
    >
    > $source_file = $_FILES['userfile']['name']; //ok exist (is a file from
    > the local drive
    >
    > $destination ="/public_html/info/uploads"; //I think that's the map I make
    >[/color]
    You are already in /public_html/info/uploads directory, as you have
    done *ftp_chdir* to change the current working directory at server.

    The syntax for *ftp_fput* is:

    bool ftp_fput ( resource ftp_stream, string remote_file, resource
    handle, int mode [, int startpos] )

    So, modify your code accprdingly:

    $source_file = $_FILES['userfile']['name'];>
    $destination_fi le = "remote_filenam e";

    $fp = fopen($source_f ile, 'r');

    ftp_fput ( $conn_id,$desti nation_file,$fp , FTP_BINARY );

    ftp_close($conn _id);
    fclose($fp);

    --
    Hope it will help,
    Rahul Anand

    Comment

    • Alain Dhaene

      #3
      Re: upload ftp

      HI,
      I rewrite the code but i seems it doesn't works.


      $source_file = "course.txt ";
      $destination_fi le = "copy.txt"; //but this txt doesn't exist yet. I want
      put the $source_file (local drive) on the ftp server.(in the map uploads)

      $fp = fopen($source_f ile, 'r');

      ftp_fput ( $conn_id,$desti nation_file,$fp , FTP_BINARY );



      I get follow errors:

      Warning: fopen(cursisten .txt): failed to open stream: No such file or
      directory in /home/school/public_html/result.php on line 29

      cursisten.txt

      Warning: ftp_fput() expects parameter 3 to be resource, boolean given in
      /home/school/public_html/result.php on line 43



      Alain




      "Rahul Anand" <rahulanand_bis @rediffmail.com > schreef in bericht
      news:628e2f7b.0 401292158.73f69 e14@posting.goo gle.com...[color=blue]
      > "Alain Dhaene" <alain.dhaene@w orldonline.be> wrote in message[/color]
      news:<bvbnl8$cs a$1@news.worldo nline.be>...[color=blue][color=green]
      > > HI,
      > >
      > > I have follow problem. I want upload a file to a map on a ftp server.
      > >
      > > I make a connection to a ftp server. That's ok.
      > > Then I make a directory
      > >
      > > ftp_chdir($conn _id,"/public_html/info"); //ok
      > >
      > > if(ftp_mkdir($c onn_id,"uploads ")) print ("File is created!"); //ok
      > >
      > > ftp_chdir($conn _id,"/public_html/info/uploads"); //ok ?????
      > >
      > >
      > >
      > > $source_file = $_FILES['userfile']['name']; //ok exist (is a file[/color][/color]
      from[color=blue][color=green]
      > > the local drive
      > >
      > > $destination ="/public_html/info/uploads"; //I think that's the map I[/color][/color]
      make[color=blue][color=green]
      > >[/color]
      > You are already in /public_html/info/uploads directory, as you have
      > done *ftp_chdir* to change the current working directory at server.
      >
      > The syntax for *ftp_fput* is:
      >
      > bool ftp_fput ( resource ftp_stream, string remote_file, resource
      > handle, int mode [, int startpos] )
      >
      > So, modify your code accprdingly:
      >
      > $source_file = $_FILES['userfile']['name'];>
      > $destination_fi le = "remote_filenam e";
      >
      > $fp = fopen($source_f ile, 'r');
      >
      > ftp_fput ( $conn_id,$desti nation_file,$fp , FTP_BINARY );
      >
      > ftp_close($conn _id);
      > fclose($fp);
      >
      > --
      > Hope it will help,
      > Rahul Anand[/color]


      Comment

      • Rahul Anand

        #4
        Re: upload ftp

        "Alain Dhaene" <alain.dhaene@w orldonline.be> wrote in message news:<bvd1ft$p6 b$1@news.worldo nline.be>...[color=blue]
        > HI,
        > I rewrite the code but i seems it doesn't works.
        >
        >
        > $source_file = "course.txt ";
        > $destination_fi le = "copy.txt"; //but this txt doesn't exist yet. I want
        > put the $source_file (local drive) on the ftp server.(in the map uploads)[/color]

        $destination_fi le contains just the file name, a plain string
        variable.

        That means your local file will be uploaded to ftp server with name
        $destination_fi le

        [color=blue]
        >
        > $fp = fopen($source_f ile, 'r');[/color]

        I guess problem is here. Please provide file name (if not in current
        local directory, give full path, relative or absolute). Ensure your
        local file is placed there.
        [color=blue]
        > ftp_fput ( $conn_id,$desti nation_file,$fp , FTP_BINARY );
        >
        >
        >
        > I get follow errors:
        >
        > Warning: fopen(cursisten .txt): failed to open stream: No such file or
        > directory in /home/school/public_html/result.php on line 29
        >
        > cursisten.txt
        >
        > Warning: ftp_fput() expects parameter 3 to be resource, boolean given in
        > /home/school/public_html/result.php on line 43
        >
        > Alain[/color]

        Hope it will help.

        --
        Rahul Anand

        Comment

        Working...