470,819 Members | 1,582 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,819 developers. It's quick & easy.

PHP - ftp_put() not uploading

162 100+
ftp_put() is not working. this is what i have.

[PHP]
$host = "www.site.com";
$ftp_user_name = "username";
$ftp_user_pass = "password";

// declair files
$remote_file = "ITS_BLI_0".$_POST['id'].".csv"; // root level
$file = "/upload/ITS_BLI_0".$_POST['id'].".csv"; // this file dir is root/manager/posts/

// connect to remote server
$hostip = gethostbyname($host);
$conn_id = ftp_connect($hostip);

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

// IMPORTANT!!! turn passive mode on
ftp_pasv ( $conn_id, true );

if ((!$conn_id) || (!$login_result)) {

echo "FTP connection has failed!";
echo "Attempted to connect to $host for user $ftp_user_name";
die;

} else {

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {

echo "successfully uploaded $file<br>";

} else {
/** IM GETTING THIS ERROR **/
echo "There was a problem while uploading $file to $host<br>";

}

// close the connection
ftp_close($conn_id);

}

[/PHP]
  • I have done the following allready.
  • Used both FTP_ASCII and FTP_BINARY in ftp_put().
  • Passive mode must be on.
  • I have tried ftp_fput().

Is there a fix? Or maybe a way to view why its erroring on ftp_put().

thanks, [es]
Apr 13 '06 #1
3 20322
Banfa
9,065 Expert Mod 8TB
You haven't said which of your output messages you are getting when you attempt, however I question this piece of code

[php]
$file = "/upload/ITS_BLI_0".$_POST['id'].".csv"; // this file dir is root/manager/posts/
[/php]

is the upload directory really at the root of your directory structure?

Even if it appears atthe root of your hosted website that is not the root of that machines dirctory structure and php works off the machine root not the site root.

So I would say check that the soruce file is where you think it is, easily done with the file_exists function

[php]
if (file_exists($file))
{
echo "The file $filename exists";
}
else
{
echo "The file $filename does not exist";
}[/php]
Apr 13 '06 #2
empiresolutions
162 100+
thats helped alot thanks. i fixed it. simple pathing error.

old -

$file = "/upload/ITS_BLI_0".$_POST['id'].".csv";

new -

$file = "../../upload/ITS_BLI_0".$_POST['id'].".csv";
Apr 13 '06 #3
try my post here...

http://www.thescripts.com/forum/showthread.php?p=2710795#post2710795
Jul 24 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Joseph Markovich | last post: by
1 post views Thread by balzano_1 | last post: by
2 posts views Thread by Udo Pecher | last post: by
5 posts views Thread by tripwater | last post: by
1 post views Thread by excession | last post: by
5 posts views Thread by Alex | last post: by
reply views Thread by sushil | last post: by
1 post views Thread by PehJota | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.