FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 4th, 2004, 05:49 AM
cjhoward cjhoward is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 87 cjhoward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 41 m
Reputation Power: 5
ftp_get only txt files in ftp

I need to ftp_connect to a server and dowload all txt files in a directory (which contains jpg and txt files).

The following code will ftp_connect to a server and download (ftp_get) a SPECIFIED file. But I won't know the new filename generated everyday that I need to download. So how do I download ALL txt files in the remote directory and save as same filename in local directory? Thanks.


PHP Code:
// define some variables
$local_file 'newlocal.txt';
$server_file 'remotefile.txt';
$ftp_server "ftp.server.net";
$ftp_user_name "user";
$ftp_user_pass "pass";


// set up basic connection
if ($conn_id ftp_connect($ftp_server)) {
   echo 
"Connected to ".$ftp_server."";
   }else{
   echo 
"Can't connect to ".$ftp_server."";
       exit();
}

// login with username and password
if ($login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass)) {
   echo 
"Logged on to ".$ftp_server."<br>User: ".$ftp_user_name."<br>Pass: ".$ftp_user_pass."";
   }else{
   echo 
"Can't logon as User: ".$ftp_user_name."<br>Pass: ".$ftp_user_pass."";
       exit();
}

// try to download $server_file and save to $local_file
if (ftp_get($conn_id$local_file$server_fileFTP_BINARY)) {
   echo 
"Successfully written to $local_file\n";
} else {
   echo 
"There was a problem\n";
   exit();
}

// close the connection
if ($conn_id) {
   
ftp_close($conn_id);


Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > ftp_get only txt files in ftp


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway