By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 2,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Copying file from hosted remote sever to local machine

P: n/a
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($ftp_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 myfilesdirectory
if (ftp_chdir($conn_id, "myfilesdirectory")) {
echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
echo "Couldn't change directory\n";
}

if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

Oct 27 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.


I'm not sure if I've understood what you are doing so bear with me. The
code is fine, but it has to be executed on the /local/ machine, not the
/remote/ machine. The remote machine has the FTP server which the local
machine communicates with using the FTP protocol.

---
Steve

Oct 27 '05 #2

P: n/a
I don't think you will get it to work, The best you can probably get
is to make it offer a file to you (ala download), but since the remote
server does not control your computer it can't really make it do
anything like automatically accept a file - unless you had some sort of
special client plugin to allow the server to do such things. (ala
software update)

If you are doing a bunch of files you can pack them up on the server
calling some zip app and then ask the client to download them.

Oct 28 '05 #3

P: n/a
Eureeka
Ive found a solution. Visual basic offers functions that use the 'Internet
Transfer Control' which can communicate with remote server and manipulate,
put and get files to and from it as well as other interesting things.
If anyone is interested do a search on Microsoft website for 'Internet
Transfer Controls' Here is a link to an excellent downloadable example which
pretty much does everything I need

http://support.microsoft.com/default...b;en-us;286809

Happy programming
Ian

<la***@portcommodore.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I don't think you will get it to work, The best you can probably get
is to make it offer a file to you (ala download), but since the remote
server does not control your computer it can't really make it do
anything like automatically accept a file - unless you had some sort of
special client plugin to allow the server to do such things. (ala
software update)

If you are doing a bunch of files you can pack them up on the server
calling some zip app and then ask the client to download them.

Oct 28 '05 #4

P: n/a
C.
So I guess:

file_put_contents($localfilename,
file_get_contents("ftp://{$user}:{$password}@{$host}{$remote}"));

doesn't work?

C.

Oct 28 '05 #5

P: n/a

Ian Davies wrote:
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?


Simple, old fashioned way of automating a task:

ftp < commands.txt

Oct 29 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.