PHP FTP and Playstream

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
aakiny1
Forum Newbie
Posts: 2
Joined: Mon Dec 05, 2005 1:34 pm

PHP FTP and Playstream

Post 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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

why not try removing all your error suppression, i.e. " @" and see what comes up.
aakiny1
Forum Newbie
Posts: 2
Joined: Mon Dec 05, 2005 1:34 pm

PHP FTP and Playstream

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
Post Reply