Jump to content

Recommended Posts

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 [i]that[/i] respect, i can delete files, delete folders too... But i cannot download or upload files via ftp.

[code]
<?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); 
?>
[/code]
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.
[code]
$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); 
?>
[/code]

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 [i]is[/i] 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...
Link to comment
https://forums.phpfreaks.com/topic/13747-ftp-php-issues-unsolved/
Share on other sites

[quote]<?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); 
?>[/quote]

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

Thank you,
Karthikeyan
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'].

[code]
<?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); 
?>
[/code]

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 ;)
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_[i]computername[/i]. 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.
[quote author=craygo link=topic=99533.msg392567#msg392567 date=1152199413]
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_[i]computername[/i]. 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.
[/quote]
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 :)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.