Forum Moderators: coopster
I got a problem.
I have to implement a FTP system on the server of my website.
I realized a file named ftp.php that's in the directory /my so that to recall it I have to digit: http://www.example.com/my/ftp.php
This is just a test file but every time I call it, the answer is:
Warning: ftp_put(C:\bolero.mid) [function.ftp-put]: failed to open stream: No such file or directory in /web/htdocs/www.example.com/home/my/ftp.php on line 20.
The line 20 is the following one:
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
The script is here below ( with domain username and password fake because I'm not here to make publicity of my website) ... the problem I think are the variables:
$source_file
$destination_file
But I tried many configuration of them ... for instance $source_file I tried with
"C:\bolero.mid";
"C:/bolero.mid";
"C:\\bolero.mid";
"C://bolero.mid";
even for the $destination_file I tried
"/bolero.mid";
"/my/bolero.mid";
"/web/htdocs/www.example.com/home/my/bolero.mid";
Without any positive result ... the answer stills the same ... could you help me please ? Where do I wrong ? I thank you very much in advance for the help
<?php
// set up basic connection
$ftp_server = "ftp.example.com";
$ftp_user_name = "username";
$ftp_user_pass = "passwd";
$source_file = "C:\\bolero.mid";
$destination_file = "/bolero.mid";
$conn_id = @ftp_connect($ftp_server);
// login with username and password
$login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) ¦¦ (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
[edited by: dreamcatcher at 7:33 am (utc) on Jan. 13, 2009]
[edit reason] use example.com. Thanks. [/edit]
... and if I would like to transfer a local file from my pc to my site via php ftp script ... is it possible ?
As regards FTP... not really, at least probably not the way you are thinking(?) The FTP extension within PHP allows you to connect as an FTP client to an FTP server. Perhaps from your web server to a server elsewhere. If you were running your PHP/FTP app in a web server on your local machine then yes you could send/upload local files to a remote FTP server (providing you 'local' files are within your webspace).
However, regular file uploads are usually handled by the HTTP protocol - see coopster's post.