I am using ftp_get to transfer a file from a secure location, to a temp location. (working)
Once at the temp location i need to have the file automatically download to the clients local machine. Something like a right click "save as" action. How do i do this? I'm thinking its done with headers but not sure.
My Current Code is below. Thanks for all responses. -
-
// define some variables
-
$ftp_server = "123.45.67.890";
-
$local_file = '/scratch1/test/'.$name;
-
$server_file = $name;
-
-
echo "server file: $server_file <br>";
-
-
$ftp_user_name = "5a515";
-
$ftp_user_pass = "m5n5o5";
-
-
// set up basic connection
-
$conn_id = ftp_connect($ftp_server);
-
-
// login with username and password
-
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
-
-
if ($login_result) echo "Successfully connected<br>";
-
-
//change directory
-
ftp_chdir($conn_id, "tts");
-
ftp_chdir($conn_id, "incoming");
-
-
// try to download $server_file and save to $local_file
-
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)){
-
-
echo "Successfully written to $local_file\n";
-
-
}else{
-
-
echo "<br>There was a problem\n";
-
}
-
-
// close the connection
-
ftp_close($conn_id);
-
-
2 4980 dlite922 1,584
Recognized Expert Top Contributor
I am using ftp_get to transfer a file from a secure location, to a temp location. (working)
Once at the temp location i need to have the file automatically download to the clients local machine. Something like a right click "save as" action. How do i do this? I'm thinking its done with headers but not sure.
My Current Code is below. Thanks for all responses. -
-
// define some variables
-
$ftp_server = "123.45.67.890";
-
$local_file = '/scratch1/test/'.$name;
-
$server_file = $name;
-
-
echo "server file: $server_file <br>";
-
-
$ftp_user_name = "5a515";
-
$ftp_user_pass = "m5n5o5";
-
-
// set up basic connection
-
$conn_id = ftp_connect($ftp_server);
-
-
// login with username and password
-
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
-
-
if ($login_result) echo "Successfully connected<br>";
-
-
//change directory
-
ftp_chdir($conn_id, "tts");
-
ftp_chdir($conn_id, "incoming");
-
-
// try to download $server_file and save to $local_file
-
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)){
-
-
echo "Successfully written to $local_file\n";
-
-
}else{
-
-
echo "<br>There was a problem\n";
-
}
-
-
// close the connection
-
ftp_close($conn_id);
-
-
You're on the right track:
FIRST OF ALL. I really hope that's not the username and password but a fake one, if not you're secure location is not so secure now. Besides FTP is not encrypted anyway. But I digres.
manipulating the headers to the type of file is exactly what you need to do.
If that file is public, just copy it to a directory in your websiter and give the public the link to the file.
if it's private (based on user) then you need to change the header to whatever type of file it is, use php fread() to read the file, print it, and voila!
...or so I think in theory. I'm no PHP master but that's how I'd tackle it.
Good Luck
Thanks dlite.
This is the solutions. Thanks to NogDog. -
// try to download $server_file and save to $local_file
-
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)){
-
header('Content-Length: '. filesize($local_file));
-
header('Content-Type: application/octet-stream');
-
header('Content-Disposition: attachment; filename="'.basename($local_file).'"');
-
header('Content-Transfer-Encoding: binary');
-
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
-
readfile($local_file); // send the file
-
exit; // make sure no extraneous characters get appended
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: toedipper |
last post by:
Hello,
php and mysql
I have the code below. It's a mixture of my hand coding and dreamweaver
created code. It's meant to log a download and then start the download.
I can do the first part ok as I can check the db and see that there is
an entry but the download won't start, it just sits there and nothing
downloads.
|
by: Jim Hubbard |
last post by:
Assuming Microsoft want .Net to be the next big thing in Microsoft
programming, why is the .Net Framework 1.1 an optional download on the
Windows Update site? I'd think that it should be required.
Jim Hubbard
|
by: Ian Davies |
last post by:
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...
|
by: Bob Moore |
last post by:
We have a requirement to put a client onto machines intended for some
telephony work. The database access will be via ASP.Net pages, and
that's fine, but the telephony stuff requires access to some legacy
servers. I've prototyped the client itself as Winforms/C# (which was
NOT fun for a C++ curmudgeon like me, but I'll live).
The problem is, I'd like to be able to ensure that the user is always
running the latest client (our current fat...
|
by: Alex |
last post by:
I'm trying to make simple ftp client, used the following article for base:
http://www.devarticles.com/c/a/PHP/Building-An-FTP-Client-With-PHP/3/
All works, I can login, see list of files, but except ftp_put and ftp_get
functions. They return always false. I tried to set passive mode, it doesn't
help.
Any advice will be appreciated.
| |
by: clintonG |
last post by:
To all Microsoft partners and customers who have been unable to download
recently or access ASP.NET documentation from the msdn2 website and for all
of those customers who have been lied to and misled by some of the sleazy
MVPs and the lying cockroaches that Microsoft has working for the company...
Microsoft has serious problems with their servers and websites. The entire
MSDN server farm and all download resources MSDN manages has been...
|
by: irfan.mohammed |
last post by:
Dear All,
I need your help,i am using ftp_get for getting the file from remote
machine.now i am able to save only at one location.i want the user to
select the directory any where in the computer and able to save it.
Thanks in advance
Irfan
|
by: unicorn |
last post by:
Hi guys,
I have moved my site from one domain to another. it worked perfectly on old domain, ftp_put(), ftp_delete() - i.e. FTP upload and remove scripts work fine, but... i have problem using ftp_get() wicth shows me error, and says :
Warning: ftp_get() : Error opening 4.gif in /home/mydomain/public_html/down_att.php on line 43
Couldn't download file '4.gif' .
i have checked connection, path. well if i change path (ftp...
|
by: empiresolutions |
last post by:
I have some scripts that when initiated by a link click will FTP a 1G+ file from a secure server to another server using ftp_get(). Once ftp_get() is complete i then user Content Headers to open a "save as" dialog box. (working good to this point).
Since the files are so large there will be times when a user loses connection or something else that interrupts the download happens. Now what i need is to be able to "finish" the download from the...
|
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...
|
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...
| |
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |