Jump to content


Photo

FTP php issues... UNSOLVED


  • Please log in to reply
8 replies to this topic

#1 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 05 July 2006 - 04:00 PM

Another problem:

I can connect to my server via ftp, indeed - i can not only login with ftp, but create a new folder as well - so it is working in that respect, i can delete files, delete folders too... But i cannot download or upload files via ftp.

<?php
$ftp_server = 'servername';
$ftp_user_name = 'username;
$ftp_user_pass = 'password';
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to server");
$ftp_login = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("Cannot login to the ftp server");
if($ftp_login){
  echo "logged in!<br />";
  ftp_mkdir($conn_id, "testdir");
} else {
  echo "not logged in<br />";
}
ftp_close($conn_id);   
?>
Now it prints out the logged in!, and also creates the testdir - so it does log in without issue.

However, remove that part and insert the more required function: Upload a file. This is related to my earlier http upload issue, which worked on apache but not windows (and couldn't get it working either  ???). Swapped to ftp thinking it would be simple to use that instead, but when trying - it doesn't work.
$file = $_FILES['userfile']['name']; // comes from a form that submits to this file, the filename is correct and working just fine
$endfile = 'file.txt';

if(ftp_put($conn_id, $endfile, $file, FTP_ASCII)) {
 echo "file upload successful";
} else {
 echo "file not uploaded";
}
ftp_close($conn_id);   
?>

Now it always says "file not uploaded". I've tried binary transfer, tried changing filenames, paths, etc. The file is selected via input type="file" and this is the method as per my previous post that successfully uploaded via http transfer to my apache server. Therefore I know that the file to upload is selected correctly, obviously it's the actual upload that isn't working and I cannot find any php.ini settings that are relevant to it. The filesize is small, under 2kb - so it doesn't exceed any settings in php.ini for max filesize.

Does anyone have any bright ideas, clues, experiences etc with this sort of thing? Running a local windows server IIS 6, and like I said - I can make folders (suggest any other functions if you wish).
Oh yes, I can log into the local server with ipswitch ftp program, and copy/upload/download files all day - so the userlogin etc is perfectly fine, and the permissions must be fine too...

#2 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 05 July 2006 - 04:50 PM

<?php
$ftp_server = 'servername';
$ftp_user_name = 'username;
$ftp_user_pass = 'password';
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to server");
$ftp_login = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("Cannot login to the ftp server");
if($ftp_login){
  echo "logged in!<br />";
  ftp_mkdir($conn_id, "testdir");
} else {
  echo "not logged in<br />";
}
ftp_close($conn_id); 
?>


there is one parse error...
$ftp_user_name = 'username; replace this line with $ftp_user_name = 'username';

Thank you,
Karthikeyan

www.karthi.us

#3 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 06 July 2006 - 07:52 AM

Fraid that was a "copy paste" error, as the username/password (and host) were all changed from the real values.

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 July 2006 - 08:12 AM

Can you kindly exspalin the issue slowly please cheers.

and the first problam was corrected by a member so include the code properly cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 06 July 2006 - 08:34 AM

The problem is this:

I am trying to use php for ftp uploads. I can connect and log into the server. Once logged in, I can return  the list of files in the directory, I can delete files, I can create a directory and I can delete said directory - all without any trouble or issues at all.
What I am failing to do is to upload or download files via the ftp connection using ftp_put, ftp_get methods.
Here is the code I am trying to use - its taken from php.net's example under ftp_put. The filename is coming from an <input type="file"> as given under http uploads, in the $_FILES['userfile']['name'].

<?php
$file = $_FILES['userfile']['name'];
$endfile = 'file.txt';
$ftp_server = 'servername';
$ftp_user_name = 'username';
$ftp_user_pass = 'password';
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to server");
$ftp_login = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("Cannot login to the ftp server");
if($ftp_login){
  echo "logged in!<br />";
  if(ftp_put($conn_id, $endfile, $file, FTP_ASCII)) {
   echo "file upload successful";
  } else {
  echo "file not uploaded";
  }
}
ftp_close($conn_id);   
?>

I have changed the FTP_ASCII to binary instead, and still no joy. The file i am trying to upload is a txt file, called mike.txt for now, although I have also renamed it to match the "endfile" name specified. I am running on a windows webserver, with iis 6 and mssql as my database (although that obviously has no bearing on this issue :D). As I say, I can do other functions, just not upload/download files.

Thanks for anyone taking the time to read/think/suggest/point anything that they can think of to me, and help is much appreciated. Any further info needed will be posted on request ;)

#6 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 06 July 2006 - 03:00 PM

Hoping that someone can still help, sorry for the bump... just a little bit desperate.

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 July 2006 - 03:04 PM

this is probably a dumb question, but when you create your directory, what is the default read/write permissions? maybe it won't upload because it does not have the proper permissions on the directory.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 06 July 2006 - 03:23 PM

When running IIS you have to give the web account access to the folder you wish to write to. By default the web account is IUSR_computername. You need to give this account modify access to the folder. when giving access you should also click advance and make sure you click the option to make it recursive.

#9 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 06 July 2006 - 03:50 PM

When running IIS you have to give the web account access to the folder you wish to write to. By default the web account is IUSR_computername. You need to give this account modify access to the folder. when giving access you should also click advance and make sure you click the option to make it recursive.

Thanks, I have tried this - but it still fails to make any changes/difference at the moment. I've pretty much granted (as it's a local server, not available to the internet) everything access to everything in order to try and get it to work - all security settings on folders have been set to allow for modify (and the others that go with it), and still no joy.

Has reached the point that we are about to install linux on a partition instead - as to be honest, working with windows has been non stop headaches from day one...

Many thanks for putting things forward though, sadly its impossible to see whether I actually did things right or not, but I think i did :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users