I have been playing with a PHP page I am writing to connect to my FTP server on the local drive and I am encountering problems.
What I am trying to do is to get an FTP page setup so that I can press a button and the page will then: –
Connect to FTP server
Login with user name and password
Turn on Passive mode
Change to the htdocs folder
upload a file called data.txt to the current working directory.
upload a file called go.php to current working directory
verify the file is in place (not yet implemented)
close the connection
then output a URL to the file called go.php, eg [url]http://localhost/go.php?src=data.txt
go.php processes the file and then deletes it as well as the file called go.php
Now this is the issue…
In the FTP server I can see the connection open up, the login process OK and then turns on passive mode, gets the CWD, changes to the htdocs folder, attempts to upload the data.txt file but then returns an error saying that the file name is invalid despite being valid! and I can see the full path to the file!
I have looked at many examples of using the basic PHP ftp functions which is what I need to use and all the demonstrations show the same method of working.
basically they layout is something like
[code=php] $con = ftp_connect(“localhost”); // ftp_server
// login with username and password
$log = ftp_login($con, “test”, “password”);
if($log){ // we are logged in.
$cwd = ftp_pwd($con); // the current working directory
// turn passive mode on
ftp_pasv($con, true);
// upload a file
ftp_chdir($con, “htdocs”); // change to that directory
ftp_put($con, “data.txt”, “data.txt”, FTP_ASCII);
ftp_put($con, “go.php”, “go.php”, FTP_ASCII);
// close the connection
ftp_close($con);
}
echo ($log?”Done.”:”Error!”);
and this working but not uploading.
What am I missing or doing wrong?
Any help is appreciated.