473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Copying file from hosted remote sever to local machine

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
5 6032
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
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
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
C.
So I guess:

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

doesn't work?

C.

Oct 28 '05 #5

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: POnfri | last post by:
Hi, I have a problem in a peace of code were i'm doing a file copy using File.Copy. The Source is local and the target is a remote machine. Example: File.Copy(C:\temp\hi.txt,...
1
by: david | last post by:
Wehen locally access it, the browser can show me the test form for the Webmethod. But when I access it from remote machine, I get: The test form is only available for requests from the local...
0
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute with...
5
by: TB | last post by:
Hi All: This news group is proving to be great help on my path towards mastering ASP.NET thanks to all of you helpful souls out there. I am looking forward to the day when I can contribute...
0
by: mlfblom | last post by:
Hi, I am running visual studio 2005 on a Vista Ultimate client. I have created a remote site on a Windows 2003 R2 server. This site has about 100 aspx, many App_Code files and several references...
1
by: iitt2007 | last post by:
I have a XLS file on local machine and would like to copy all the columns to a new SQL table on the 'remote' (not local sql server) using SQL scripts. I tried following : select * into...
1
by: thanawala27 | last post by:
Hi, My perl scripts run on a unix server which i access from a windows machine. I wanted to copy a file from the local HD to this server. But the problem is, whenever i try to access a file...
7
by: mrmoosehead | last post by:
OK. I am trying to embed a control in a webpage that will allow local access to the TAPI system to make and query phone calls. In a nutshell. Anyway, I am aware that there are many security...
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.