#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Question for ftp_put


    Hello I'm new in this forum and I studying php from soon .Now i studying ftp function but I have problem with ftp_put. I try upload text file on my host with this function my code is so
    PHP Code:
    <?php
    $newfile
    ="hello.txt";
    $filedestination="D:/test/beach.txt";
    $s=ftp_connect("ftp.0adz.com");
    $l=ftp_login($s,$username,$password);
    if((!
    $s)||(!$l)) { print('error');}else{print("connect");}
    file($filedestination);
    ftp_get($s,$newfile,$filedestination,FTP_ASCII);
    ?>
    I use 0adz.com host .I want upload file form my computer .please tell me where is my error and thanks a lot from now !I wait for your answers.
  2. #2
  3. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Is it:
    a) Printing out "error", or
    b) Printing out "connect"

    "file($filedestination);" wouldn't be doing anything...

    You have file_get() instead of file_put()
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by dmittner
    Is it:
    a) Printing out "error", or
    b) Printing out "connect"

    "file($filedestination);" wouldn't be doing anything...

    You have file_get() instead of file_put()
    script is printing connect .I use file($filedestination); because before I call function ftp_put I must open text document so i read from my book which i studying php.
  6. #4
  7. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by ookamisan
    script is printing connect .I use file($filedestination); because before I call function ftp_put I must open text document so i read from my book which i studying php.
    You're either misunderstanding the book or the book is wrong.

    file_put() just takes source/destination file path (which you're providing), not the handle of an open file. And even if it did require a handle to an open file, that's not what file() does.

    Anyway, it sounds like it should be getting all the way through, so just replace this:

    PHP Code:
    ftp_get($s,$newfile,$filedestination,FTP_ASCII); 
    with:

    PHP Code:
    if (ftp_put($s,$newfile,$filedestination,FTP_ASCII)) {
     echo 
    "successfully uploaded $file\n";
    } else {
     echo 
    "There was a problem while uploading $file\n";

    That'll at least verify that the problem is with the FTP send attempt, which is probably the case. Then we'll need to figure out why that's not working.

IMN logo majestic logo threadwatch logo seochat tools logo