ftp_put() problems

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

    #1

    ftp_put() problems

    Hello, I am having problems with the ftp_put() function. I can login
    via shell prompt.

    Does anyone know why the ftp_put() function may not work? I went to the
    php site and followed the directions. I am connecting because I am not
    getting an error. I am also logging in with the username and password
    because I am not getting an error here as well. But so far no matter
    what I do, the file will not upload.

    Any help with this would be great.

    code:
    $query = "select Server, UserName, Password, Destination_Pat h,
    ServerType from company";

    $result = @mysql_query($q uery);

    $row = @mysql_fetch_ar ray($result);

    if (!empty($row["Server"]))
    {
    $hostip = gethostbyname($ row["Server"]);
    $conn_id = ftp_connect($ho stip);

    // set up basic connection
    //$conn_id = ftp_connect($ro w["Server"]);

    // login with username and password
    $login_result = ftp_login($conn _id, $row["UserName"],
    $row["Password"]);

    // check connection
    if ((!$conn_id) || (!$login_result ))
    {
    $value = "FTP connection has failed!<br>
    Attempted to connect to ".$row["Server"]." for user ".$row["UserName"];
    exit;
    }

    // IMPORTANT!!! turn passive mode on
    //tried this and it did not help
    //ftp_pasv ( $conn_id, true );





    //parameters are ftp_put($conn_i d, $destination_fi le, $source_file,
    FTP_BINARY)

    $upload = ftp_put($conn_i d, $row["Destination_Pa th"]."/".
    strtolower(trim ($HTTP_POST_FIL ES['userfile']['name
    '])), strtolower(trim ($HTTP_POST_FIL ES['userfile']['name
    '])), FTP_BINARY);

    if (!$upload)
    echo $upload."<br><b r>Did not upload to ftp server.";

    // close the FTP stream
    ftp_close($conn _id);
    }


    I am not getting any errors and the file is not getting uploaded.

    -my server var holds the URl of the server ex. 'test.com'

    - my destination file var holds the path temp

    so the destination path when I echo it is temp/my file

    so the ftp_put() is getting passed

    ftp_put($conn_i d, 'temp/myfile', 'myfile', ftp_binary);

    This is the first time I have ever used this function so please bear
    with me. I have researched it and no one seems to have this problem.
    Most people complain that the file seems to get uploaded but its file
    size is 0. Right now, my page runs and nothing happens. My permissions
    on the server are correct, the folder I am trying to upload to exists,
    the username and pass are correct and I can login via shell prompt as
    well.

    Any ideas?
    Thanks

  • Mike Willbanks

    #2
    Re: ftp_put() problems

    > $upload = ftp_put($conn_i d, $row["Destination_Pa th"]."/".[color=blue]
    > strtolower(trim ($HTTP_POST_FIL ES['userfile']['name
    > '])), strtolower(trim ($HTTP_POST_FIL ES['userfile']['name
    > '])), FTP_BINARY);[/color]


    Make sure the destination path is a single filename... no folders, if it
    is in a different folder change directory's to that folder.

    Next make sure that your source file has the full path otherwise how is
    it going to know what file to send?

    also claiming binary is a good thing but this script looks like it
    directly takes a users input and places it on the server... so what
    happens when you get a text file... if this is user input you should
    really screen out some files and check for viruses against that file.

    Thats about it.

    Mike

    Comment

    • tripwater

      #3
      Re: ftp_put() problems

      Thank you for the reply. I will try what you suggested. One thing I am
      curious about is why would I need the full path to the source file?

      For example, why do I not have to pass in the full path when just
      uploading a file like this:

      move_uploaded_f ile($HTTP_POST_ FILES['userfile']['tmp_name'],
      $path."/".$HTTP_POST_FI LES['userfile']['name']) I do not give it the
      full path, just the tmp name of the file. I thought that having access
      to the post file[userfile][name] would be enough.

      Thanks again for your time

      Comment

      • tripwater

        #4
        Re: ftp_put() problems

        Another thing I am confused about (forgive my lack of knowledge here)
        but I do not see how to change directories from the site server. For
        example if I call

        // current directory
        echo getcwd();

        I will get the CWD of the current file I am in on the website, not the
        current folder I am trying to ftp into remotely. If I call
        chdir('public_h tml/temp') this is not on the sever the website you are
        currently uploading from.

        So I do not understand how to chg dirs on a remote server that you are
        trying to ftp to using php and it not look at the server you are
        currently sitting on.

        Can you please clarify because I am really confused.

        Thanks

        Comment

        • What_yeah

          #5
          Re: ftp_put() problems

          I have tried uploading directly to the root folder and it still does
          not work. Can maybe someone show me a example of the proper way to use
          this function? I have looked at a few examples and I thought I had my
          code laid out like the examples. I have also check file/folder
          permissions and this is not an issue.

          Thanks again

          Comment

          • empiresolutions
            New Member
            • Apr 2006
            • 162

            #6
            I am haveing the same issue with ftp_put() not working. I have ftp_pasv() on, pathed right. please help

            Comment

            Working...