Page 1 of 1

PHP FTP and Playstream

Posted: Mon Dec 05, 2005 1:55 pm
by aakiny1
Hi everyone,
I am a newbie to these kinds of forums so please go easy.
Situation/Question.
I have a php file on my webserver which connects to a playstream ftp server. After the connection has been made I try to list the contents for the directory and get nothing. However, when I FTP using other tools I am able to list the directory contents. The end goal is to be able to use the php ftp functions to upload files to the playstream ftp server. But for now, I will settle for trying to figure out why I am not getting a directory listing. For those that may wonder I do have ftp access to the playstream ftp server.

Below is my php code, what am I doing wrong?

Code: Select all

<?php 
	$ftpServer = "ftp.playstream.com"; 
	$ftpUser = "myusername";
	$ftpPass = "mypassword";

	set_time_limit(0); 
	
	$conn = @ftp_connect($ftpServer) 
	or die("Couldn't connect to FTP server"); 
	
	$login = @ftp_login($conn, $ftpUser, $ftpPass) 
	or die("Login credentials were rejected"); 
	
	$workingDir = ftp_pwd($conn); 
	echo "You are in the directory: $workingDir<br>"; 
	
	//Get a list of files and directories in the current working directory
	$fList = @ftp_rawlist($conn, $workingDir); 
	
	//Display list
	if(is_array($fList)) { 
		for($i = 0; $i < sizeof($fList); $i++) { 
			echo $fList[$i] . "<br>"; 
		} 
	} else { 
		echo "$workingDir contains no files.<br>"; 
	} 
		
	ftp_quit($conn); 

?>
Thanks all for your help in advance :-)
Jr.

Hawleyjr:
aakiny1 Welcome to DevNet. Please read the following link regarding posting code in the forum.

Posting Code Guide

Posted: Mon Dec 05, 2005 8:50 pm
by Charles256
why not try removing all your error suppression, i.e. " @" and see what comes up.

PHP FTP and Playstream

Posted: Mon Dec 05, 2005 11:00 pm
by aakiny1
First thanks Hawleyjr, for the posting review guide. I have not gone through it all but I am sure the rest will be good reading. Also thanks Charles256, for taking the time to look at the code and give a response, at least now I know the @ sign supresses error messages.

Now for the solution,

First I reliazed, I needed to turn on passive mode ftp_pasv ($conn, true). That got me past the problem recorded in my original post. I then encountered the problem of actually uploading my file, suffice it to say the following line of code was the correct ftp_put line ...
ftp_put($conn, $_FILES["formfileField"]["name"], $_FILES["formfileField"]["tmp_name"], FTP_BINARY).

That's it ... I hope this helps someone some day ;-).

Jr.

Posted: Tue Dec 06, 2005 8:30 am
by m3mn0n
Hey and welcome to the community.

I'll move this to the PHP Code forum, as it's the better place for this type of thread.