Helpful Information
 
 
Category: FTP Help
ftp_put error - need help

<?php
$server="ftp.myserver.com";
$user="myuser";
$pass="mypass";

// Connect & login to FTP server
$ftp=ftp_connect($server) or die ("Problem with FTP server !");
$conn=ftp_login($ftp,$user,$pass) or die ("Problem logining on to FTP server");

$dir=ftp_pwd($ftp); // Stores current directory as $dir

$file=$dir."/uploaded/datafile.txt"; // name of file we want to upload

$localfile = "C:\testfile.txt";

$upload=ftp_put($ftp,$file,$localfile,ftp_binary) or die ("Problem with upload");

?>

RESULT : Warning: error opening
C:\datafile.txt in ......script name

Can anyone help ?

If tried replacing C:\ with C:/ and C:// and lots of other combinations !

Please Help

v10

What OS, I know you are running a windoze machine, but is it NT,2000,XP? If so, does the web server have permissions to read the directory you are trying to access?

Try moving the file you are trying to upload into the same directory that the script is located and see if that works.

You might also want to ftp_chdir to the exact directory you are wanting to upload to.

Ok, first of all it should be $localfille="c:\\testfile.txt"; or $localfile='c:\testfile.txt'; and then, why do you upload .txt file in binary? Should be FTP_ASCII (note the capital letters, same with ftp_binary, should be capital)

Ok, My Pc is running Win98SE and the server is UNIX.

The script now reads as follows :

<?php
$server="ftp.server.com";
$user="user";
$pass="pass";

// Connect & login to FTP server
$ftp=ftp_connect($server) or die ("Problem with FTP server !");
$conn=ftp_login($ftp,$user,$pass) or die ("Problem logining on to FTP server");

$dir=ftp_pwd($ftp); // Stores current directory as $dir

$file=$dir."/uploaded/datafile.txt"; // name of file we want to upload

$localfile = 'C:\testfile.txt';

$upload=ftp_put($ftp,$file,$localfile,FTP_ASCII) or die ("Problem with upload");

?>


Still no Joy, Please help.... this is bugging me .....!:(

Thanks for the help,

V10

"no joy" as in....

No joy as in it's still not working.

Can you help Mr. Capone ?

I read somewhere else that ftp_put can only move files from one server to another, but I don't believe that, as that wouldn't be the normal use of ftp ?

I've also seen this type of problem posted all over the place with similar type replies and no solution but I'm not a quitter.

Surely this is possible, and someone out there knows a solution.

It could be you.

C'mon, put your thinking cap on ;)

V10

>>I read somewhere else that ftp_put can only move files from one server
>> to another, but I don't believe that, as that wouldn't be the normal use
>> of ftp ?
BS. What you've just describes is called fxp'ing, and it is widely popular in..uhm... not so legitimate purposes.

What I meant is, what erros do you get? Try echoing each var before ftp_put and see if it says what you want.

Ok it now reads :

<?php
$server="ftp.server.com";
$user="user";
$pass="name";

// Connect & login to FTP server
$ftp=ftp_connect($server) or die ("Problem with FTP server !");
$conn=ftp_login($ftp,$user,$pass) or die ("Problem logining on to FTP server");

$dir=ftp_pwd($ftp); // Stores current directory as $dir

$file=$dir."/ftp/datafile.txt"; // name of file we want to upload

$localfile = 'C:\testfile.txt';

echo "Connected to : $server as user : $user on Directory : $dir <br>";
echo "The plan is to upload this file : $localfile to this directory : $file on the server <br>";

$upload=ftp_put($ftp,$file,$localfile,FTP_ASCII) or die ("Problem with upload");

?>

Result :

Connected to : ftp.server.com as user : user on Directory : /
The plan is to upload this file : C:\testfile.txt to this directory : /ftp/datafile.txt on the server

Warning: error opening C:\testfile.txt in /home/ftp/ftpscript.php on line 19
Problem with upload


Appreciate the help al, what do you think ?

V10

What do I think? I think this is probably the longest thread about the dummest mistake ;) You're on unix host, and you're trying to open file c:\testfile.txt on server's hdd. Sure enough, it gives errors, and you know why? There is no c:\testfile.txt, heck there is no c:\ there is / So you'll have to edit your path accordinally.

hmmm, I'm trying to upload from the users hdd to my unix server.

The file C:\testfile.txt is on the same pc as the browser right ?

I know there is no C drive on my server but the file isn't on my server, it's on a local pc with a browser running win98 that has a C drive.

Am I seriously not with it today or what ?

What way should I address the C drive of the users pc or can I ?

Thanks for bearing with me :p


V10

PHP is server side langauge and therefore every file you request comes from server.
>>What way should I address the C drive of the users pc or can I?
You simply can't. At least not directly. What you could do though is to first make users upload file to server and then put it on ftp.










privacy (GDPR)