SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ftp_put woes, please help

    Im' trying to ftp all files in a given directory to a remote server. Since the number of files will vary, I'm using a while loop in which the ftp_put happens, like so:

    PHP Code:
    <?
    //ftp server-user-pass info omitted (tested, no error there)
    $ftp_dir "sub/dir";
    $src_dir "/path/to/files";

    // set up basic connection
    $conn_id ftp_connect($ftp_server);

    // login with username and password
    $login_result ftp_login($conn_id ,$ftp_user_name ,$ftp_user_pass);

    // check connection
    if ((! $conn_id ) || (!$login_result)){
            echo 
    "FTP connection has failed!";
            echo 
    "Attempted to connect to $ftp_server for user $ftp_user_name";
            exit; 
        } else {
            echo 
    "Connected." ;
        }

    if ( 
    $handle =opendir('$src_dir')) {
        
        while (
    false !== ($file =readdir ($handle))){
        
    $upload ftp_put($conn_id$ftp_dir "/" $file$src_dir "/" $fileFTP_BINARY);        
        }
        
    //print_r($array);
        
    closedir ($handle);
    }
    ?>
    However, nothing gets ftp-ed to the remote server. What am I doing wrong?
    Thanks for any help!

  2. #2
    SitePoint Addict streetlife's Avatar
    Join Date
    Mar 2004
    Location
    D-Town
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you're connection is good, and your syntax is good, then I'd say that most likely you don't have permission to write to that directory.

  3. #3
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by streetlife
    Well, if you're connection is good, and your syntax is good, then I'd say that most likely you don't have permission to write to that directory.
    Thanks for your reply. The perms on that dir are okay - when the script hangs, it has already "uploaded" one zero k file with the correct name. So it can access the dir, starts to write, but times out... I think it has something to do with max execution time (30secs I believe), so I tried overriding that with set_time_limit(30) - no dice.

    I'm trying to call this script with a crontab by the way, so if anyone knows of a better way to have a bunch of files ftp'ed to a remote server on a regular timeschedule (once per day), please let me know!

    ...anyone? ...Bueller?

  4. #4
    SitePoint Addict streetlife's Avatar
    Join Date
    Mar 2004
    Location
    D-Town
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it has something to do with max execution time (30secs I believe), so I tried overriding that with set_time_limit(30) - no dice.
    So you over-rode the max execution time of 30 seconds with a max execution time of 30 seconds?!

    What is the size of the file/files that you're trying to transfer? I've seen it when the ftp server is really slow and it could be the case here. Have you tried ftp'ing from the shell to see what happens? If it works good from the shell then you could try doing the transfer via the shell using the exec() function.

  5. #5
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by streetlife
    So you over-rode the max execution time of 30 seconds with a max execution time of 30 seconds?!
    I over-rode with set_time_limit(). From the manual:
    When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
    Quote Originally Posted by streetlife
    What is the size of the file/files that you're trying to transfer?
    8Kb... there's about 16 of those to be uploaded during the while loop.

    Quote Originally Posted by streetlife
    If it works good from the shell then you could try doing the transfer via the shell using the exec() function.
    Hmmm okay, but then, how would I automate that task? Can you put a shell command in a crontab? I'm quite the newbie when it comes to ssh/shell stuff - thanks for helping out...

  6. #6
    SitePoint Addict streetlife's Avatar
    Join Date
    Mar 2004
    Location
    D-Town
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I over-rode with set_time_limit(). From the manual:
    I'm just making the point that if you did an over-ride of the original maximum execution time of 30 seconds by setting it as 30 seconds, then you didn't over-ride anything because you set it to what it already was.

    Anyways, you definately don't have to worry about 128kb of data being transfered in a space of 30 seconds, under normal circumstances, but it could be that the remote ftp server you are attempting to transfer to is dead slow. It appears to me that your code is correct, and the connection is definately there and you can also write to the remote site. I think you need to test your code with another reliable ftp server to see how it works, if it works good then the problem is with the ftp server itself and not your code, thus narrowing down your area to troubleshoot.

  7. #7
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by streetlife
    I'm just making the point that if you did an over-ride of the original maximum execution time of 30 seconds by setting it as 30 seconds, then you didn't over-ride anything because you set it to what it already was.
    Erh... but that's not what the manual says, no? Setting set_time_limit() in the middle of a script will, to my understanding, *add* to the default execution time. I might be wrong though...

    Quote Originally Posted by streetlife
    I think you need to test your code with another reliable ftp server to see how it works, if it works good then the problem is with the ftp server itself and not your code, thus narrowing down your area to troubleshoot.
    The ftp server (at dreamhost.com, quite a popular hosting service) is very fast and reliable... ftp-ing those files the "normal way" (using Transmit, in my case) takes no more than 5 seconds, tops.

    I seem to have hit a brick wall here, and I'm running out of solutions... And I'm also curious as to how you guys out there go about setting up a daily ftp-routine like this - I mean, maybe there's a better solution that doesn't use php?

    I really appreciate your willingness to help very much, thanks!

  8. #8
    Dinah-Moe Humm mudshark's Avatar
    Join Date
    Dec 2003
    Posts
    1,072
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thought I'd follow up on this...: turns out the problem was that I had been trying to run the script from my localhost, ftp-ing to the remote server. I tried running the script from one remote server to another, and it now transfers all the files -- at least the filenames show up, but they are all zero k! Aaaaargh...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •