SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 30
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help moving a .zip file to an ftp server please?

    Hi

    I have a .zip file and a .csv file that I need to send to an ftp server on a daily basis. Can anyone tell me how I would go about setting that up please?

    Thansk for any help in advance.

  2. #2
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this a general question on how to use ftp or a question how to do it in php scripting language from your website to another server?
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    sorry for not being very clear in my initial question. I have a .zip file and a .csv file that sit on my webserver which I need to automatically send to another ftp server at a set time every day.

    Can anyone give me some pointers as to how to go about setting this process up?

    Thanks in advance.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cron

  5. #5
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that was useful.

    JayP is semi right, Cron would take care of the once a day thing but you need to look into finding a FTP class or reading up on ftp with php (Google) .
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well they did just say pointers ;D
    It doesn't sound like PHP is actually involved, other than the forum we're in!

  7. #7
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it is if the op wants to move files from their server to an FTP server which is remote. Cron is only a timer which acts as a trigger. It won't move the files.

    Cron can however trigger a php script which can instruct php to move the files.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or, perhaps more sensibly, trigger an FTP application

  9. #9
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Why not use PHP FTP functions

    PHP Code:
    $file 'path_and_file_to_send';
    $remote_file 'name_of_file_on_receiving_server';
    $conn_id ftp_connect('ftpserveraddress');
    $login_result ftp_login($conn_id'username''password');
    if (
    ftp_put($conn_id$remote_file$fileFTP_ASCII)) {
       echo 
    "File successfully uploaded to server.<br /><br />";
    }else{
       echo 
    "There was a problem uploading file to server<br /><br />";
    }
    ftp_close($conn_id); 
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  10. #10
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jay.P View Post
    Or, perhaps more sensibly, trigger an FTP application
    Such as? - Please name one and how to use it.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  11. #11
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The 'ftp' command seems like a solid start!

    Just makes more sense to me to use the native FTP application for something to basic than to run a PHP script to do the same thing!

  12. #12
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not all servers have it though - thats the problem and why we're suggesting the use of phps own ftp functions
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  13. #13
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's be honest, I think the OP hates us anyway

  14. #14
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ??? - Might hate you for your one word replies and stuff but the rest of us have actually tried to help.
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  15. #15
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My relevant one-word answer that would point them in the right direction or...? Sigh. Why be so uptight on a damn forum; y'asked me to name an FTP application like you've never heard of it before, just to be awkward eh. The chances of the host not having it is surely on par with the chances of the PHP FTP extension not being installed so stop being difficult Please calm with the blunt attitude because it appears you're stressing me out!
    -unsubscribe

  16. #16
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Curious, since it hasn't been asked nor stated:
    What is the relationship between Server A (SA) and Server B (SB)? Meaning not just the physical/scripting but also the people. - The point being, is there a reason why SB cannot have a script to get the files from SA. rather than SA trying to upload?

    Also (old but still relative) might look at #5 here REQEST : Upload a file to another remote server - Codewalkers

  17. #17
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @ litebearer

    no reason, its equally possible to initiate the transfer from either side, but normally you only have control over one side of the equation. Take for example an XML feed of real estate properties, a third party site may give you FTP access to a certain directory to upload your XML file into. You would have no way of installing a script on their server to fetch the file, but you could install a script on your side to put the file inot the remote directory.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  18. #18
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have 3 options to Transfer Files Via FTP in PHP:

    1. use php ftp functions
    2. use fopen/fwrite
    3. use curl

    Depending on your host some of the options could be disabled. However I doubt all them are disabled.

  19. #19
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks for all the replies on this!! Appreciate the help.
    I will look into CRON once I actually get a php file set up to do this manually. I'm trying the ftp_put option but I'm getting the following error:

    Warning: ftp_pasv() expects parameter 1 to be resource, null given in /myfile.php on line 3

    Warning: ftp_put() [function.ftp-put]: Ok to send data. in /myfile.php on line 9
    There was a problem uploading file to server

    Here's the actual file:

    PHP Code:
    ftp_pasv($resourcetrue);

    $file 'filename.csv';
    $remote_file 'filename.csv';
    $conn_id ftp_connect('ftpaddress');
    $login_result ftp_login($conn_id'myusername''mypassword');
    if (
    ftp_put($conn_id$remote_file$fileFTP_ASCII)) {
       echo 
    "File successfully uploaded to server.<br /><br />";
    }else{
       echo 
    "There was a problem uploading file to server<br /><br />";
    }
    ftp_close($conn_id); 
    Any ideas why, other then I've obviously got something wrong somewhere?

  20. #20
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I check the destination ftp server I can see that the script has created a file with the correct name but the file is 0kb!! Any suggestions as to whats wrong with this?

  21. #21
    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)
    Try this...
    PHP Code:
    <?php
    function ftp_upload_file($host$user$pass$file$mode FTP_BINARY$port 21){
      
      if(
    false === is_readable($file)){
        
    trigger_error(sprintf('FTP: %s cannot be opened'$file), E_USER_NOTICE);
        return 
    false;
      }
      
      if(
    FTP_BINARY !== $mode){
        
    $mode FTP_ASCII;
      }
      
      
    $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;
      }
      
      
    $status ftp_put($connbasename($file), $file$mode);
      
      
    ftp_close($conn);
      
      return 
    $status;
    }
    PHP Code:
    if(ftp_upload_file('example.org''username''password''path/to/local/file.txt'){
      
    #yay
    }else{
      
    #boo

    @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.

  22. #22
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Sorry obviously being a bit thick with this. I've put the code you posted into 1 file uploaded it and now I'm getting a syntax error!! What am I doing wrong?

    PHP Code:

    $host
    ="ftp.site.co.uk";
    $user="myusername";
    $pass="mypassword";
    $file="myfile.csv";

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

    if(
    ftp_upload_file('ftp.site.co.uk''myusername''mypassword''/home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.csv'){
      
    #yay
      
    echo"Cool";
    }else{
      
    #boo
      
    echo"Not Cool";


  23. #23
    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)
    Try this, I fixed my rather sloppy coding.
    PHP Code:
    <?php
    function ftp_upload_file($host$user$pass$file$mode FTP_BINARY$port 21){
      
      if(
    false === is_readable($file)){
        
    trigger_error(sprintf('FTP: %s cannot be opened'$file), E_USER_NOTICE);
        return 
    false;
      }
      
      if(
    FTP_BINARY !== $mode){
        
    $mode FTP_ASCII;
      }
      
      
    $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;
      }
      
      
    $status ftp_put($connbasename($file), $file$mode);
      
      
    ftp_close($conn);
      
      return 
    $status;
    }

    if(
    ftp_upload_file('ftp.site.co.uk''myusername''mypassword''/home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.csv')){
      echo 
    'Cool';
    }else{
      echo 
    '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.

  24. #24
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    According to another user who posted a note on php.net (strangely with identical code to yours also trying to upload a .csv file) it was the mode indicator.

    As I understood it ASCII mode was purely for text files. Can anyone confirm?
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.

  25. #25
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I'm now getting the following error:

    Warning: ftp_put() [function.ftp-put]: Ok to send data. in /home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.php on line 30
    Not cool

    Here's the full code I have now:

    PHP Code:

    <?php
    $host
    ='ftp.address.co.uk';
    $user='myuser';
    $pass='mypass';
    $file='/home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.csv';

    function 
    ftp_upload_file($host$user$pass$file$mode=FTP_BINARY$port21){
      
      if(
    false === is_readable($file)){
        
    trigger_error(sprintf('FTP: %s cannot be opened'$file), E_USER_NOTICE);
        return 
    false;
      }
      
      if(
    FTP_BINARY !== $mode){
        
    $mode FTP_ASCII;
      }
      
      
    $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;
      }
      
      
    $status ftp_put($connbasename($file), $file$mode);
      
      
    ftp_close($conn);
      
      return 
    $status;
    }

    if(
    ftp_upload_file('ftp.address.co.uk''myuser''mypass''/home/mysite/domains/mysite.co.uk/public_html/Feeds/myfile.csv')){
      echo 
    'Cool';
    }else{
      echo 
    'Not cool';
    }


    ?>


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
  •