Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3388

Show
Ignore:
Timestamp:
03/21/08 11:14:11 (9 months ago)
Author:
lmartin92
Message:

Now instead of listing the top level subdirs it lists every subdir including sudirs subdirs.
May take a while on a large server to do certain things.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/lmartin/ftp/tango/io/vfs/FtpFolder.d

    r3387 r3388  
    77 
    88//fix flatness 
    9  
    109module tango.io.vfs.FtpFolder; 
    1110 
     
    1514import tango.io.Conduit; 
    1615import tango.text.Util; 
     16 
     17private FtpFileInfo[] getFiles(FTPConnection ftp, char[] path = "") { 
     18    FtpFileInfo[] orig = ftp.ls(path); 
     19    FtpFileInfo[] temp; 
     20    foreach(FtpFileInfo inf; orig) { 
     21        if(inf.type == FtpFileType.dir) { 
     22            temp ~= inf; 
     23        } 
     24    } 
     25    foreach(FtpFileInfo inf; temp) { 
     26        orig ~= getFiles((ftp.cd(inf.name) , ftp)); 
     27        ftp.cdup(); 
     28    } 
     29    return orig; 
     30} 
    1731 
    1832class FtpFolderEntry: VfsFolderEntry { 
     
    115129        ftp_ = new FTPConnection(); 
    116130        ftp_.connect(toString_, username_, password_, port_); 
    117         FtpFileInfo[] fis = ftp_.ls(name_); 
     131        FtpFileInfo[] fis = getFiles(ftp_, name_); 
    118132        ftp_.close(); 
    119133 
     
    149163            try { 
    150164                ftp_.mkdir("diw"); 
    151                 if(ftp_.exist("diw")) { 
    152                     ftp_.rm("diw"); 
    153                     writeable_ = true; 
    154                 } else 
    155                     writeable_ = false; 
     165                ftp_.rm("diw"); 
     166                writeable_ = true; 
    156167            } catch(Exception e) { 
    157168                writeable_ = false; 
     
    223234        ftp_ = new FTPConnection(); 
    224235        ftp_.connect(toString_, username_, password_, port_); 
    225         FtpFileInfo[] fis = ftp_.ls(); 
     236        FtpFileInfo[] fis = getFiles(ftp_); 
    226237        ftp_.close(); 
    227238        uint size; 
     
    238249        ftp_ = new FTPConnection(); 
    239250        ftp_.connect(toString_, username_, password_, port_); 
    240         FtpFileInfo[] fis = ftp_.ls(); 
     251        FtpFileInfo[] fis = getFiles(ftp_); 
    241252        ftp_.close(); 
    242253        uint size; 
    243254 
    244255        foreach(FtpFileInfo fi; fis) { 
    245             if(fi.type != FtpFileType.unknown || fi.type != FtpFileType.file || fi.type != FtpFileType.other) 
     256            if(fi.type == FtpFileType.dir) 
    246257                size++; 
    247258        } 
     
    257268        ftp_ = new FTPConnection(); 
    258269        ftp_.connect(toString_, username_, password_, port_); 
    259         FtpFileInfo[] fis = ftp_.ls(); 
     270        FtpFileInfo[] fis = getFiles(ftp_); 
    260271        ftp_.close(); 
    261272        uint size; 
     
    463474        } 
    464475        if(doFilter_) { 
    465             FtpFileInfo[] infs = ftp_.ls(); 
     476            FtpFileInfo[] infs = getFiles(ftp_); 
    466477            FtpFileInfo[] toReturn; 
    467478            if(useFilter_) { 
     
    491502            return toReturn; 
    492503        } else 
    493             return ftp_.ls(); 
     504            return getFiles(ftp_); 
    494505    } 
    495506 
     
    507518} 
    508519 
    509 debug(UnitTest)
     520debug(UnitTest)
    510521    /* 
    511522     *  
    512523     */ 
    513524 
     525    import tango.io.vfs.model.Vfs; 
     526    import FtpFolder; 
     527    import tango.net.ftp.FtpClient; 
    514528    import tango.io.Stdout; 
    515529    import tango.util.Convert; 
    516530 
    517531    int main() { 
    518          
     532 
    519533        //variables 
    520          
     534 
    521535        VfsFolder folder; 
    522536        VfsFile file; 
     
    525539        VfsFolderEntry entry; 
    526540        char[] toPrint; 
    527          
     541 
    528542        //init code 
    529          
    530         entry = new FtpFolderEntry("ftp.digitalmars.com", ""); 
     543 
     544        entry = new FtpFolderEntry("127.0.0.1", "", "lmartin92", "asunset!", 21); 
    531545        Stdout("Inited entry.").newline.flush; 
    532546        folder = entry.open(); 
    533         //folder = new FtpFolder("ftp.digitalmars.com", ""); 
     547       //folder = new FtpFolder("ftp.digitalmars.com", ""); 
    534548        Stdout("Inited folder.").newline.flush; 
    535549        folders = folder.tree(); 
    536550        Stdout("Inited tree.").newline.flush; 
    537         file = folder.file("dmd.1.00.zip"); 
     551        file = folder.file("client.exe"); 
    538552        Stdout("Inited file.").newline.flush; 
    539         files = folders.catalog("dmd"); 
     553        files = folders.catalog("cli"); 
    540554        Stdout("Inited catalog.").newline.flush; 
    541555        Stdout("Initialization Passed.").newline.newline.flush; 
     
    543557        //print information gatherable from all of 
    544558        //the variables 
    545          
     559 
    546560        //entry 
    547561        Stdout("Folder exists: ").flush; 
    548562        toPrint = to!(char[])(entry.exists()); 
    549563        Stdout(toPrint).newline.flush; 
    550          
     564 
    551565        //folder 
    552566        Stdout("Folder:").newline.flush; 
    553567        toPrint = "\n\t writeable: " ~ to!(char[])(folder.writable()); 
    554568        toPrint ~= "\n\t name: " ~ folder.name(); 
    555         toPrint ~= "\n\t path: " ~folder.toString(); 
     569        toPrint ~= "\n\t path: " ~ folder.toString(); 
    556570        Stdout(toPrint).newline.flush; 
    557          
     571 
    558572        //folders 
    559573        Stdout("Folders: ").newline.flush; 
     
    561575        toPrint ~= "\n\t #of Folders: " ~ to!(char[])(folders.folders()); 
    562576        toPrint ~= "\n\t Total Objects: " ~ to!(char[])(folders.entries()); 
    563         toPrint ~= "\n\t Folders Occupies Space: " ~ to!(char[])(folders.bytes()); 
     577        toPrint ~= "\n\t Folders Occupies Space: " ~ to!(char[])( 
     578                folders.bytes()); 
    564579        Stdout(toPrint).newline.flush; 
    565          
     580 
    566581        //file 
    567582        Stdout("File: ").newline.flush; 
     
    571586        toPrint ~= "\n\t path: " ~ file.toString(); 
    572587        Stdout(toPrint).newline.flush; 
    573          
     588 
    574589        //files 
    575590        Stdout("Files: ").newline.flush; 
     
    578593        Stdout("\n\t #of Files: ").flush; 
    579594        Stdout(files.files()).newline.flush; 
    580          
     595 
    581596        return 0; 
    582597    } 
    583  
    584 
     598