By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,738 Members | 1,822 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,738 IT Pros & Developers. It's quick & easy.

FTP problem

P: n/a
Well, I must say that I am new to working with FTP and am having problems
despite the good help I have recieved. I have been working with
code supplied by Janwillem Borleffs and have been able to get it to
connect to the ftp server on my dev machine (red hat/apache). What I am
trying to do is create a directory but the directory is not being created
(at least I don't see it in the expected directory) from an administrative
form so that annonomous users can upload files into it.

I think I am missing something here.
Expand|Select|Wrap|Line Numbers
  1.      $ftp = fsockopen("", 21, $errno, $errstr, 30);
opens the ftp connection. This address hosts several dev sites
including the one I need to create a directory in which I will name
site1_root. The URL to the site on my dev machine is
"". (what I type in the bwroser to get to the home

Expand|Select|Wrap|Line Numbers
  1.   fputs($ftp, "cwd /site1_root/uploads/custom"); 
supposed to change directories. If I understand it correctly, this code is
writing to the handle($ftp) which should allow it to point to the proper
where I want to create the new folder.

Below is the code for the whole page: When try to execute it, I get no
error msgs from the fputs command, but
Expand|Select|Wrap|Line Numbers
  1.    if
  2. (!file_exists("../uploads/custum/".$foldername)) { 
fails and let's
me know the folder does not exist.

The uploads folder has permissions set to '0777' for now.

I guess I'm all over the place in my comments here ... and I hate to ask
this question, but why doesn't this work?

Irvin <><
__________________________________________________ _________

<title>Untitled Document</title>
<meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

if($Submit) {
if (!file_exists("../uploads/custum/".$foldername)) {

$user = 'username';
$pass = 'password';
$dirname = "../uploads/custum/".$foldername;

// Connect
$ftp = fsockopen("", 21, $errno, $errstr, 30);
fputs($ftp, "cwd /site_root/uploads/custom");

if (!$ftp) {
echo "$errno: $errstr<br>\n";
// Authenticate
if(!fputs($ftp, "user $user\r\n")) { echo "User Failed.<br>"; }
fgets($ftp, 1024);
if(!fputs($ftp, "pass $pass\r\n")) { echo "Pass Failed.<br>"; }
fgets($ftp, 1024);

// Make dir
if(!fputs($ftp, "mkd $dirname\r\n")) { echo "MKDIR Failed.<br>"; }

// Close
fputs($ftp, "quit\r\n");


if (!file_exists("../uploads/custum/".$foldername)) {
$errTxt.="An unidentified error was encountered while<br> trying to
create the folder <b>'uploads/custum/$foldername'</b>.";
$errTxt.="<font-color='green'>The folder
<b>'uploads/custum/$foldername'</b> was sucessfully created.</font>";
$errTxt.="The folder <b>'uploads/custum/$foldername'</b> already esists.";

<form name="form1" method="post" action="">
<table width="321" border="0" align="center" cellpadding="5"
cellspacing="0" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF" class="mainheading">
<td><p>Add a New Custum Folder <span class="content"><br>
</span></p> </td>
<tr class="content">
<td align="right"><div align="center">Enter the name of the folder
you wish to add:</div></td>
<tr class="content">
<td align="right"><div align="center">
<input name="foldername" type="text" class="content" id="foldername"
value="<?php echo $foldername?>" size="50">
<tr class="content">
<td><div align="center">
<input name="Submit" type="submit" class="content" value="Add
<tr class="content">
<td><div align="center"><span class="contentBoldRed"><?php echo
$errTxt ?></span></div></td>
<tr class="content">
<td bgcolor="#FFFFFF"><div align="center"><a href="browse.php">Return
to Folder Contents </a></div></td>

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.