473,388 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 21216
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

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

Similar topics

0
by: Joseph Markovich | last post by:
I'm trying to write a script for my users to be able to upload large files, and now I am unsure what exactly I am doing wrong. My script is based on the one in the PHP manual. <?php if(isset(...
1
by: balzano_1 | last post by:
Hi, im trying to upload a file from a client (windows) to an ftp server (linux), i deciede to use some of php`s functions to connect and authenticate etc.. i only wish to put a file on the server,...
2
by: Udo Pecher | last post by:
I apply the following code test.php $upload =ftp_put($conn_id,"test.jpg","$dat",FTP-BINARY); where $dat is a local filename which I like to move via FTP. "test.jpg" ist the filename on the...
5
by: tripwater | last post by:
Hello, I am having problems with the ftp_put() function. I can login via shell prompt. Does anyone know why the ftp_put() function may not work? I went to the php site and followed the...
1
by: excession | last post by:
I've got a script which uploads a few files to a remote server. The problem is the ftp_put command hands and the script eventually times out. What is even more strange is sometime it works fine. ...
3
by: Carlos | last post by:
Hello Forum, I would appreciate it if you could recommend settings to use auto-vacuum in my version 7.4 database. I am uploading several thousands records in the database at a rate of ~1 second...
5
by: Alex | last post by:
I'm trying to make simple ftp client, used the following article for base: http://www.devarticles.com/c/a/PHP/Building-An-FTP-Client-With-PHP/3/ All works, I can login, see list of files, but...
0
by: sushil | last post by:
Hello Frnds, I am getting problem in uploading file from php script. The error is : Code - $upload = ftp_put($conn_id,$filemax,$src,FTP_BINARY); Output - Resource id...
1
by: PehJota | last post by:
I'm kinda new to PHP, and I'm trying to make a simple FTP upload script. It successfully connects to the server and logs in, but it can't upload. The transfer mode I use normally is ASCII (like I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.