Hello
I am trying to use php to automate the copying of a file from my remotely
hosted directory to my computer. I have put together the following but it
will only do the copying from one directory to another on the remote server.
Reading the postings on these functions they suggest that it can be done but
it appears to be the case if your are hosting your site on the same machine
you want to copy the files to. Does anyone know if there are functions in
php to do the transfer from remote server to my machine or if the code below
will acheive this with modification?
Ian
<?php
$ftp_server = "xxxxxxxx";
$ftp_user = "xxxxxxx";
$ftp_pass = "xxxxxx";
$local_file = 'myfile.txt';
$server_file = 'myfile.txt';
// set up a connection or die
$conn_id = ftp_connect($ft p_server) or die("Couldn't connect to
$ftp_server");
$login_result = ftp_login($conn _id, $ftp_user, $ftp_pass);
// check connection
if ((!$conn_id) || (!$login_result )) {
die("FTP connection has failed !");
}
// try to change the directory to myfilesdirector y
if (ftp_chdir($con n_id, "myfilesdirecto ry")) {
echo "Current directory is now: " . ftp_pwd($conn_i d) . "\n";
} else {
echo "Couldn't change directory\n";
}
if (ftp_get($conn_ id, $local_file, $server_file, FTP_BINARY)) {
echo "Successful ly written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn _id);
I am trying to use php to automate the copying of a file from my remotely
hosted directory to my computer. I have put together the following but it
will only do the copying from one directory to another on the remote server.
Reading the postings on these functions they suggest that it can be done but
it appears to be the case if your are hosting your site on the same machine
you want to copy the files to. Does anyone know if there are functions in
php to do the transfer from remote server to my machine or if the code below
will acheive this with modification?
Ian
<?php
$ftp_server = "xxxxxxxx";
$ftp_user = "xxxxxxx";
$ftp_pass = "xxxxxx";
$local_file = 'myfile.txt';
$server_file = 'myfile.txt';
// set up a connection or die
$conn_id = ftp_connect($ft p_server) or die("Couldn't connect to
$ftp_server");
$login_result = ftp_login($conn _id, $ftp_user, $ftp_pass);
// check connection
if ((!$conn_id) || (!$login_result )) {
die("FTP connection has failed !");
}
// try to change the directory to myfilesdirector y
if (ftp_chdir($con n_id, "myfilesdirecto ry")) {
echo "Current directory is now: " . ftp_pwd($conn_i d) . "\n";
} else {
echo "Couldn't change directory\n";
}
if (ftp_get($conn_ id, $local_file, $server_file, FTP_BINARY)) {
echo "Successful ly written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn _id);
Comment