לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 28-10-2005, 00:39
צלמית המשתמש של דור
  דור דור אינו מחובר  
 
חבר מתאריך: 09.04.02
הודעות: 8,000
מחלקת FTP לשימוש חופשי

בעקבות הפרסום של Bumpy, החלטתי לפרסם מחלקת FTP שכתבתי (זו מחלקה מצומצמת, השארתי לכם הרבה מקום לדמיון)
אתם מוזמנים להוסיף פונקציות משלכם או לשנות את הפונקציות הקיימות.

בלי יותר מדי דיבורים, הנה המחלקה:
קוד PHP:
 class ftp
{
    public    
$ftp_result;
    public    
$num_operations;
    public    
$num_failed_operations;
    protected 
$ftp_connection;
    protected 
$ftp_login;
    protected 
$host;
    private   
$password;
    private   
$username;
    
    
/**
     * FTP Class by dorkiaa.
     *
     * @param string $host
     * @param string $username
     * @param string $password
     */
    
function ftp($host$username$password)
    {
        
set_time_limit(0);
        
        
$this->password $password;
        
$this->username $username;
        
$this->host $host;
        
        
$this->ftp_connection ftp_connect($this->host);
        if (!
$this->ftp_connection)
        {
        
$this->log("There was an error while trying to connect {$this->host}.");
            
$this->num_failed_operations++;
            exit;
        }
        else
        {
            
$this->log("Connected seccesfuly to {$this->host}.");
        }
        
        
$this->ftp_login ftp_login($this->ftp_connection$this->username$this->password);
        if (!
$this->ftp_login)
        {
        
$this->log("There was an error while trying to login to {$this->host}.");
            
$this->num_failed_operations++;
            exit;
        }
        else
        {
            
$this->log("Login with user {$this->username}.");
        }
    }
    
    
/**
     * Uploads a file to the FTP server.
     *
     * @param string $newfilename
     * @param string $file
     */
    
public function ftp_upload($newfilename$file)
    {
        unset(
$this->ftp_result);
        
        
$this->ftp_result ftp_put($this->ftp_connection$newfilename$fileFTP_BINARY);
        
$this->num_operations++;
        if (!
$this->ftp_result)
        {
        
$this->log("There was an error while trying to upload {$file} to {$this->host}.");
            
$this->num_failed_operations++;
            exit;
        }
        else
        {
        
$this->log("The file {$file} has been seccessfuly uploaded to {$this->host}.");
        }
    }
    
    
/**
     * Downloads a file from the FTP server.
     *
     * @param string $newfilename
     * @param string $file
     */
    
public function ftp_download($newfilename$file)
    {
        unset(
$this->ftp_result);
        
        
$this->ftp_result ftp_get($this->ftp_connection$newfilename$fileFTP_BINARY);
        
$this->num_operations++;
        if (!
$this->ftp_result)
        {
        
$this->log("There was an error while trying to download {$file} to {$newfilename}.");
            
$this->num_failed_operations++;
            exit;
        }
        else
        {
        
$this->log("The file {$file} has been seccessfuly downloaded, and saved to <a href=\"{$newfilename}\">{$newfilename}.");
        }
    }
    
    
/**
     * Lists the files in a directory.
     *
     * @param string $directory
     */
    
public function ftp_list($directory '/')
    {
        unset(
$this->ftp_result);
        
        
$this->ftp_result ftp_rawlist($this->ftp_connection$directory);
        
$this->num_operations++;
        if (!
$this->ftp_result)
        {
        
$this->log("There was an error while trying to list the directory {$directory}.");
            
$this->num_failed_operations++;
            exit;
        }
        else
        {
            foreach (
$this->ftp_result as $key => $value)
            {
                echo 
strrchr($value' ')."<br />";
            }
        }
    }
    
    
/**
     * Logs the operations.
     *
     * @param string $msg
     */
    
protected function log($msg)
    {
        echo 
$msg."<br />\n";
    }


כמובן שגם אשמח להערות

נערך לאחרונה ע"י דור בתאריך 28-10-2005 בשעה 01:04.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 07:26

הדף נוצר ב 0.10 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר