Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    ftp_put() problems

    Hello, I posted this on a couple of forums (one of them 15 days ago) and I still have no answers. I have tried a few things. I know this might be a little unorthadox but instead of bogging this forum post down with copy and pasting of my other posts I will just link to my post in the other forum in hopes that someone here will take a look at it.

    Thank you for your time and any help with this

    My post on another forum

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks guys...

    Hopefully you will read this one.

    OK, I am still having this problem but I narrowed down the issue I think.

    1. I am uploading the module to the webserver.
    2. Then in the next step want to ftp same module to backup server.

    So I am calling
    Code:
    $path 	= "../modules";
    
    if (!is_dir($path))
       mkdir($path,0700);		
    	
    	
    if (!move_uploaded_file($_FILES['srcfile']['tmp_name'], $path."/".strtolower(trim($_FILES['srcfile']['name']))))
    Which works. THis uploads the module to the webserver to the set location


    then I call

    Code:
    $ftp = ftp_connect('server goes here');
    
    			
    // login with username and password
    if (ftp_login($ftp, 'username', 'password'))
       {
       ftp_pasv ( $ftp, true );
    				
    				
    				
       if (ftp_put($ftp, "public_html/temp/" . $_FILES['srcfile']['name'], $_FILES['srcfile']['tmp_name'], FTP_BINARY)) 
          {
          $message = "File uploaded";
          }
          else 
          {
          die("Could not upload file");
          }
       }
    else 
       {
       die("Could not login to FTP account");
       }
    				
    if (!empty($message)) 
       {
       echo $message;
       }
    			
    // close the FTP stream
    ftp_close($ftp);

    The only way this second FTP code works is if I comment out the first upload code,
    Code:
    $path 	= "../modules";
    
    if (!is_dir($path))
       mkdir($path,0700);		
    	
    	
    //if (!move_uploaded_file($_FILES['srcfile']['tmp_name'], $path."/".strtolower(trim($_FILES['srcfile']['name']))))
    Can anyone tell me if the problem is a ftp stream being left open and that is why I can not get the second portion of my code to work? Is there a way to get both of these to work together? I need not only to be able to upload to the webserver but ftp a backup copy to the remote server as well.

    Thank you for any help.

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    This problem was solved for me on another forum

    You used move_uploaded_file() to move the file to $path.

    Quote:
    Originally Posted by php manual.move_uploaded_file
    If the file is valid, it will be moved to the filename given by destination


    The file is no longer in temp.

    try ftp_put($ftp, $path)


  •  

    Posting Permissions

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