473,739 Members | 4,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP-FTP Downloading Files

Hello,

I am trying to download a file to my local machine using PHP. However, when
the script runs the file is placed in the folder assigned to the ftp user on
the Web server instead of downloading to my local C drive. After the
following script runs I find a file named C:\TestShowID.t xt in the user's
FTP folder on the web server. Can some tell me why this happens? The local
machine is a Windows XP machine.

Thanks,

Vic
$ftp = (object) array(
"host" = "ftp.mydomain.c om",
"user" = "us**@mydomain. net",
"password" = "password",
"remoteFile " = "ShowID.txt ",
"localFile" = "C:\\TestShowID .txt"
);
// Step one: Connect to the FTP server
if(!is_resource ($remoteRsrc=@f tp_connect($ftp->host)))
trigger_error(" Could not connect to remote "
. "server {$ftp->host}", E_USER_ERROR );

// Step two: Log into the server
if( !@ftp_login($re moteRsrc,$ftp->user,$ftp->password))
trigger_error(" Could not log on to remote "
. "server {$ftp->host}", E_USER_ERROR );

// Step Three: Attempt to copy remote file to local file
if(@ftp_get($re moteRsrc,$ftp->localFile,$f tp->remoteFile,FTP _BINARY))
echo "Remote file successfully written to {$ftp->localFile}";
else
trigger_error(" Could not import remote file.",E_USER_E RROR);

// Step Four: Close the connection
ftp_close($remo teRsrc);


Oct 31 '06 #1
1 2394
Vic Spainhower wrote:
Hello,

I am trying to download a file to my local machine using PHP.
However, when the script runs the file is placed in the folder
assigned to the ftp user on the Web server instead of downloading to
my local C drive. After the following script runs I find a file named
C:\TestShowID.t xt in the user's FTP folder on the web server. Can
some tell me why this happens? The local machine is a Windows XP
machine.

Thanks,

Vic
$ftp = (object) array(
"host" = "ftp.mydomain.c om",
"user" = "us**@mydomain. net",
"password" = "password",
"remoteFile " = "ShowID.txt ",
"localFile" = "C:\\TestShowID .txt"
);
// Step one: Connect to the FTP server
if(!is_resource ($remoteRsrc=@f tp_connect($ftp->host)))
trigger_error(" Could not connect to remote "
. "server {$ftp->host}", E_USER_ERROR );

// Step two: Log into the server
if( !@ftp_login($re moteRsrc,$ftp->user,$ftp->password))
trigger_error(" Could not log on to remote "
. "server {$ftp->host}", E_USER_ERROR );

// Step Three: Attempt to copy remote file to local file
if(@ftp_get($re moteRsrc,$ftp->localFile,$f tp->remoteFile,FTP _BINARY))
echo "Remote file successfully written to {$ftp->localFile}";
else
trigger_error(" Could not import remote file.",E_USER_E RROR);

// Step Four: Close the connection
ftp_close($remo teRsrc);
If you've read the PHP manual, you'll see that ftp_get() retrieves the
remote file (on the FTP server PHP is connecting to) and saves it as
the local file (on the machine running the PHP script).

If you've uploaded the PHP script to a web server, "local" is defined
as the web server, and subsequentally the user FTP folder.

--
Kim André Akerø
- ki******@NOSPAM betadome.com
(remove NOSPAM to contact me directly)
Oct 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4049
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
8
4040
by: Marcel | last post by:
I have a problem with a PHP page that seems to get executed twice. I am running PHP5 ISAPI on 2003 server. The script is a PHP page with a form. When the form is submitted one record have to be inserted in the database but when i look at the database after submitting the form there are two(!) records inserted so it looks like the script is executed twice. Can this be a proxy-setting or an ISA`server related subject???
1
2056
by: jdurden | last post by:
am currently woking on building this site: www.maverick-spirit.com. everything seems to be fine except the press releases page. When you click on one of the press releases in the left column under the menu, nothing comes up. I copied the code for the page directly from the press releases page on our main site: www.maverickentertainment.cc, and it is using an identical database, so I am unsure what is wrong. The issue happens when you...
0
1674
by: tsivaraman | last post by:
I am trying to build php-5.2.1 in RedHat Linux 9. I have installed libxml2-2.6.11,mysql-5.0.33,httpd-2.2.4(apache) successfully.When i do 'make' from the php directory,i get the following errors..Not able to proceed further.(./configure went smooth). I request you to provide suggestions to solve this problem. -5.2.1/include -I/lamp/php-5.2.1/main -I/lamp/php-5.2.1 -I/usr/local/ include/libxml2 -I/lamp/php-5.2.1/ext/date/lib...
26
25615
by: webrod | last post by:
Hi, I have some php pages with a lot of HTML code. I am looking for a HTML validator tool (like TIDY). TIDY is not good enough with PHP tags (it removes a lot of php code). Do you have any idea? Thanks you very much
0
7190
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
0
2751
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to `XMLRPC_CreateValueDateTime_ISO8601'
3
4611
by: jaddi1 | last post by:
Hi, I am trying to make a multi-level drop-down menu similar to what is seen here: http://www.cssplay.co.uk/menus/simple_vertical.html. My problem is that some of the menu will be populated from a database. My menu will be structured as follows: The first setion of the menu is hard-coded (the home and management sections). The rest of the menu will be populated from a database. The top level links (categories) will come from one table...
0
1346
by: Patriot89 | last post by:
I have a quick question in reference to php file extenstions... I have code for example like this... This is all located on this site www.ixalliance.com/BHS/Default (This is my nav.php file) <div class="navstyle" id="navmenu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="administration/admin.php" rel="dropmenu1">Administration</a></li>
4
4384
by: mechphisto | last post by:
I'm working on a friend's box, Fedora Core 6. It has PHP 5.1.6. I need to install mcrypt into it, and the only way I can find to do it is from source then recompile PHP. So I did all that, and got the latest PHP, 5.2.5. The ./configure finally went through OK. Make and make install. Then I restarted Apache... but the phpinfo() shows no change. It's still using 5.1.6. When I run "php -v" from command line I get a huge error I'll include...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8215
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.