The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Ftp_get doesn't download to computer
Discuss Ftp_get doesn't download to computer in the PHP Development forum on Dev Shed. Ftp_get doesn't download to computer PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 10th, 2012, 05:34 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 52 m 48 sec
Reputation Power: 0
|
|
|
Ftp_get doesn't download to computer
Hi all,
first time on here. I'm stuck and may just be understanding ftp_get () all together. Please help me.
I understand that ftp_get() should be able to download a file from the server (mine is on hostgator.com) to a folder on the local cpu. Can this be created in a chron job and done weekly without a person clicking or opening a webpage?
I seem to have it all set up to work EXCEPT I'm unsure how to set the file path to the local cpu folder. It saves it to the same folder that the .php file calling it is located instead of on my computer (as noted on many websites it will do but nobody states how to set it to your own cpu drive)?
Below is my code... Where is my thought process failing?
PHP Code:
<?php $local_file = "/Users/name/Driver_record.zip";//working from a mac currently
$server_file = "/folder1/folder2/filename.csv"; //-- Connection Settings
$ftp_server = "ip address";
$ftp_user_name = "xxxx";
$ftp_user_pass = "xxxx";
// 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);// try to download $server_file and save to local_file
ftp_pasv($conn_id, TRUE);
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);
?>
|

December 10th, 2012, 06:14 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 9
Time spent in forums: 2 h 3 m
Reputation Power: 0
|
|
|
The thing is, you write the file on the server and not on your computer (or are you executing the PHP file on your computer?). You would need to have acces to your computer from the server and your computer would have to be online everytime the cron job is executed on the server. Is that really what you want?
|

December 10th, 2012, 06:46 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
"How to set it to your own CPU drive"? What?
Your code is correct so far. Are you sure your script has permissions to write to /Users/name? Have you set error_reporting=E_ALL and display_errors=on in your php.ini, so that if there are any errors you'll see them?
|

December 11th, 2012, 02:27 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 52 m 48 sec
Reputation Power: 0
|
|
Thanks for the questions,
The executing php file with php_get() would run as a cron job on the server containing the files to be downloaded. I want to download the file to my computer, say at 2am once a week from the hosting server.
I was not seeing how to set the path from the server ftp to my computer. Simply stating "C://folder/filename.csv" wouldn't state which computer in the world it would be downloading to. So i was thinking I would have to use an ip address as well.
I already have the file created on my server. I just wanted it downloaded to a folder on my computer without having to 'click', load a webpage, or any other action on my part.
I'm now looking into ftp_put() instead of 'getting' the file from the hosting server. I think i might have to PUT the file from one server folder to a folder on the second ftp server I have.
If this is the case; which server would be local and which would be remote? I'm guessing: - local_server = server writing the file to
- remote_server = server reading the file
I hope this makes sense. If not, please let me know where my thought process is wrong.
Thanks,
BiggBrawler
|

December 11th, 2012, 02:39 PM
|
|
|
|
I think you are over complicating this. Why not share out the target directory on your computer and give your server permission to map it? Then simply copy to \\yourcomputer\yourshareddirectory\filename.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

December 11th, 2012, 03:23 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 52 m 48 sec
Reputation Power: 0
|
|
|
I.T. Dept. says to many holes in the firewall for that. Can not connect external linux server to internal file share.
|

December 11th, 2012, 03:25 PM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Are you trying to download this file to the USER'S machine (the machine running chrome/firefox/whatever and viewing your site) or to YOUR machine (the machine running apache and PHP)?
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

December 11th, 2012, 03:35 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 52 m 48 sec
Reputation Power: 0
|
|
|
I'm using a php script on hostgator shared server and want to download a file using ftp to a startlogic shared server.
|

December 11th, 2012, 03:45 PM
|
|
|
|
If you have firewalls in the way, you probably will have to do a pull from the target rather than a push from the source.
|

December 11th, 2012, 05:02 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 6
Time spent in forums: 1 h 52 m 48 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by gw1500se If you have firewalls in the way, you probably will have to do a pull from the target rather than a push from the source. |
You saved me so much grief. You're correct.
I needed to pull (ftp_get) FROM the server with the file instead of trying to push (ftp_put) TO the server I wanted it on.
Thank you so much!
|

December 13th, 2012, 03:46 AM
|
 |
Square Peg in a Round Hole
|
|
Join Date: Oct 2007
Location: North Yorkshire, UK
|
|
You CANNOT download files over FTP to your clients machine using the php functions you have there
FTP uses the client-server model; and the ftp_functions are for building/working with the client side of the model. Your website users will not be running an ftp server for you to 'upload' to
If you want to download files to YOUR own computer then get yourself a copy of filezilla or cyberduck and then look for ways to schedule that.
Also, please see this thread and, specifically, my reply
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|