Ftp local file to remote server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scoobysteve
Forum Newbie
Posts: 14
Joined: Wed Jul 30, 2014 5:19 am

Ftp local file to remote server

Post by scoobysteve »

Hi all, very new at this so sorry in advance.
I have a php script that runs every 4 hours on a cron job that creates a binary file that contains property info called atp100.blm
so the php script and the blm file are in the same location in the root of the website. I am then trying to ftp this blm file to a remote server but I cant seem to get this to work at all. The idea is to run a separate php script every 12 hours to upload this file to a company.

I keep getting this message "There was a problem while uploading atp100.blm"

Thanks in advance

Steve

Code: Select all

<?php 
$ftp_server="IP"; 
$ftp_user_name="USER"; 
$ftp_user_pass="PASS"; 
$file = "atp100.blm"; 
$remote_file = "/htdocs/atp100.blm"; 

// 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); 

// upload a file 
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) { 
    echo "successfully uploaded $file\n"; 
    exit; 
} else { 
    echo "There was a problem while uploading $file\n"; 
    exit; 
    } 
// close the connection 
ftp_close($conn_id); 
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Ftp local file to remote server

Post by Celauran »

PHP's FTP commands don't seem to provide much in the way of meaningful error reporting. You mentioned it was a binary file, though, and are trying to upload it as ASCII, which could be a source of problems.
scoobysteve
Forum Newbie
Posts: 14
Joined: Wed Jul 30, 2014 5:19 am

Re: Ftp local file to remote server

Post by scoobysteve »

thanks for your reply, I did try changing the line to if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY))
but I still got the same message. Where I am not clear is the 2 lines that state the location of the local and remote files are these meant to
be as shown or a absolute path. The php file that runs this script is in the same location as the blm file which is why I just put atp100.blm.
the remote file I tried with and without the htdocs/ as well.

$file = "atp100.blm";
$remote_file = "/htdocs/atp100.blm";
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Ftp local file to remote server

Post by Celauran »

I'm not sure; the documentation isn't clear on that. Hard to go wrong with an absolute path, though. It's worth remembering that your FTP root is not necessarily /.
Post Reply