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:
  #1  
Old August 16th, 2006, 11:37 AM
burnham burnham is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 112 burnham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 29 m 12 sec
Reputation Power: 5
Moving files on FTP server with PHP

Hello,

I am trying to write a php script that gets the files from a FTP server and then once transferred successfully moves those files to another folder so they aren't processed again.

I can't move, or rename them via php, can anyone help?

I have tried using the commands: mv and rename but with no luck

I have permissions to rename them as I have done this successfully manually.

Here is my script so far

PHP Code:
// 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); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
       echo 
"FTP connection has failed!<br>";
       exit; 
   } else {
       echo 
"Connected to $ftp_server";
   }

// get contents of the current directory
$contents ftp_nlist($conn_id".");

foreach(
$contents as $key => $file)
    {
    
$extension substr(strrchr($file"."), 1);
    echo 
"KEY $key => $file   $extension<br>";
    if(
$extension == "zip")
        {
        
// try to download $server_file and save to $local_file
        
if (ftp_get($conn_id$file$fileFTP_BINARY))
            {
               echo 
"Successfully written to $file\n<br>";
            
// move file into OLD folder
            
movefile($file$conn_id);
            }
        else
            {
               echo 
"There was a problem\n<br>";
            }
        }
    }
    
// close the FTP stream 
ftp_close($conn_id);

function 
movefile($filename$conn_id)
    {

    
$command "rename ".$filename." Old/".$filename
    echo 
"in rename zip file $command<br>";
    
// execute command
    
if (ftp_exec($conn_id$command))
        {
        echo 
"$command executed successfully\n<br>";
        
$output true;
        }
    else
        {
        echo 
"could not execute $command\n<br>";
        
$output false;
        }
    return 
$output;
    } 

Reply With Quote
  #2  
Old November 21st, 2006, 09:58 PM
jpluttme jpluttme is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 84 jpluttme User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 22 m 34 sec
Reputation Power: 9
Were you able to figure this out? I'm having the same issue.

Quote:
Originally Posted by burnham
Hello,

I am trying to write a php script that gets the files from a FTP server and then once transferred successfully moves those files to another folder so they aren't processed again.

I can't move, or rename them via php, can anyone help?

I have tried using the commands: mv and rename but with no luck

I have permissions to rename them as I have done this successfully manually.

Here is my script so far

PHP Code:
// 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); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
       echo 
"FTP connection has failed!<br>";
       exit; 
   } else {
       echo 
"Connected to $ftp_server";
   }

// get contents of the current directory
$contents ftp_nlist($conn_id".");

foreach(
$contents as $key => $file)
    {
    
$extension substr(strrchr($file"."), 1);
    echo 
"KEY $key => $file   $extension<br>";
    if(
$extension == "zip")
        {
        
// try to download $server_file and save to $local_file
        
if (ftp_get($conn_id$file$fileFTP_BINARY))
            {
               echo 
"Successfully written to $file\n<br>";
            
// move file into OLD folder
            
movefile($file$conn_id);
            }
        else
            {
               echo 
"There was a problem\n<br>";
            }
        }
    }
    
// close the FTP stream 
ftp_close($conn_id);

function 
movefile($filename$conn_id)
    {

    
$command "rename ".$filename." Old/".$filename
    echo 
"in rename zip file $command<br>";
    
// execute command
    
if (ftp_exec($conn_id$command))
        {
        echo 
"$command executed successfully\n<br>";
        
$output true;
        }
    else
        {
        echo 
"could not execute $command\n<br>";
        
$output false;
        }
    return 
$output;
    } 

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > Moving files on FTP server with PHP


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

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT