ftp_put() not working

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
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

ftp_put() not working

Post by empiresolutions »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hello all.

Im trying to ftp a .csv using ftp_put() and it is not working. Im getting an error saying that basiacally ftp_put() is returning FALSE. 
     - "There was a problem while uploading ITS_BLI_05.csv to imports.site_name.com"

My HSP says i have all the right server settings, including an updated *vhost.conf* file. below are my scripts. site_name = whatever.com. Thank for the help.

Code: Select all

/******************/
/*  VHOST.CONF   ********/
/******************/


<Directory "/var/www/vhosts/site_name/httpdocs">
php_admin_value open_basedir "/var/www/vhosts/site_name/httpdocs:/usr/share/pear:/tmp:/var/www/vhosts/site_name/httpdocs/upload:/upload"
php_admin_value safe_mode Off
</Directory>

Code: Select all

/******************/
/*  MY CODE   ********/
/******************/

	// SEND DATA TO ITS LOAD BOARD 
	// Uplaod via FTP to ITS Load Board
	// -------------------------------------------

	
	$host = "imports.site_name.com";
	$ftp_user_name = 'user_name';
	$ftp_user_pass = 'pass_word';

        // File name to be given on the $host server
	$remote_file = "ITS_BLI_05.csv";

        // file location on local server
	$file = "/upload/ITS_BLI_05.csv";

	$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 {

		echo "There was a problem while uploading $file to $host<br>";

	  }
	   
	  // close the connection
	  ftp_close($conn_id);

	}


/******************/
/*  end code   ********/
/******************/
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by empiresolutions on Tue Apr 11, 2006 10:47 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Is it resolving the hostname properly?

Maybe try it with an IP
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

i believe so by the error it is calling.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

This line is incorrect

Code: Select all

$file = /upload/ITS_BLI_05.csv";
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

typo is in the forum only. script is properly quoted.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

empiresolutions wrote:typo is in the forum only. script is properly quoted.
Whats the point of posting code that doesn't match the original entirely...who knows what else may be incorrect.

Saves everyones time and effort
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

Schooling noted Pimptastic.
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

any more bright ideas out there?
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

i fixed it. simple pathing error.

old -

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

new -

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