SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I wonder if this has something to do with the remote target path, maybe we cannot upload to the home directory of the FTP server.

    What is the full remote path you want to upload to?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  2. #27
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    After a Google or two, I noticed that a few solutions pointed to setting the FTP connection to passive mode, try this then.

    PHP Code:
    <?php
    error_reporting
    (-1);
    ini_set('display_errors'true);

    function 
    ftp_upload_file($host$user$pass$file$mode FTP_BINARY$passive true,  $port 21){
      
      if(
    false === is_readable($file)){
        
    trigger_error(sprintf('FTP: %s cannot be opened'$file), E_USER_NOTICE);
        return 
    false;
      }
      
      
    $conn ftp_connect($host$port);
      
      if(
    false === is_resource($conn)){
        
    trigger_error(sprintf('FTP: Cannot connect to %s:%s'$host$port), E_USER_NOTICE);
        return 
    false;
      }
      
      if(
    false === ftp_login($conn$user$pass)){
        
    trigger_error('FTP: Cannot login with supplied credentials'E_USER_NOTICE);
        return 
    false;
      }
      
      
    ftp_pasv($conn, (bool)$passive);
      
      if(
    FTP_BINARY !== $mode){
        
    $mode FTP_ASCII;
      }
      
      
    $status ftp_put($connbasename($file), $file$mode);
      
      
    ftp_close($conn);
      
      return 
    $status;
    }

    $result ftp_upload_file(
      
    'ftp.site.co.uk',
      
    'myusername',
      
    'mypassword',
      
    '/home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.csv'
    );

    echo 
    $result 'Cool' 'Not cool' ;
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #28
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Genius!!! That works a dream on one of the ftp sites. Having issues with the other one that I need to send to though I think this is perhaps due to passive ftp. How would I set the script to use passive mode? Also would this work for a .zip file?

    Really appreciate the help with this. Thanks again!

  4. #29
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Yay!

    It's already setup for passive, you can switch this though by passing false as the 6th param.

    PHP Code:
    $result ftp_upload_file(
      
    'ftp.site.co.uk',
      
    'myusername',
      
    'mypassword',
      
    '/home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.csv',
      
    FTP_BINARY,
      
    false
    );

    echo 
    $result 'Cool' 'Not cool' 
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #30
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm getting the following error:

    Warning: ftp_login() [function.ftp-login]: Login authentication failed in /home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.php on line 24

    Notice: FTP: Cannot login with supplied credentials in /home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.php on line 25
    Not cool

    Problem is when I use the same login details via dreamweaver I can connect to the ftp site perfectly??

    Any ideas?


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
  •