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

Changeset 3387

Show
Ignore:
Timestamp:
03/21/08 07:57:24 (9 months ago)
Author:
lmartin92
Message:

Now has a test case that uses no writing. Must set up my own localhost ftp server for that. It works pretty good. Now to support flattend FtpFolders? and FtpFolders? with custom content and it will be fully finished. Then I can work on FtpClient?

Files:

Legend:

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

    r3386 r3387  
    66 */ 
    77 
    8  //fix flatness 
     8//fix flatness 
     9 
     10module tango.io.vfs.FtpFolder; 
    911 
    1012import tango.net.ftp.FtpClient; 
     
    3739 
    3840    VfsFolder open() { 
    39         if(!exists()) { 
    40             ftp_.close(); 
    41             throw new Exception("This FTP directory is not in existence."); 
    42         } else { 
    43             ftp_.close(); 
    44             return new FtpFolder(toString_, name_, username_, password_, port_); 
    45         } 
     41        return new FtpFolder(toString_, name_, username_, password_, port_); 
    4642    } 
    4743 
     
    6359        ftp_ = new FTPConnection(); 
    6460        ftp_.connect(toString_, username_, password_, port_); 
    65         return ftp_.exist(name_) == 2 ? true : false
     61        return name_ == "" ? true : (ftp_.exist(name_) == 2 ? true : false)
    6662    } 
    6763} 
     
    8480    body { 
    8581        toString_ = server; 
    86         name_ = name != "" ? path : server
     82        name_ = path
    8783        username_ = username; 
    8884        password_ = password; 
     
    150146        if(writeableSet_) { 
    151147            return writeable_; 
    152         } else if(ftp_.exist(ftp_.mkdir("diw")))
     148        } else
    153149            try { 
    154                 ftp_.rm("diw"); 
    155                 writeable_ = true; 
     150                ftp_.mkdir("diw"); 
     151                if(ftp_.exist("diw")) { 
     152                    ftp_.rm("diw"); 
     153                    writeable_ = true; 
     154                } else 
     155                    writeable_ = false; 
    156156            } catch(Exception e) { 
    157157                writeable_ = false; 
    158158            } 
    159         } else { 
    160             writeable_ = false; 
    161159        } 
    162160        writeableSet_ = true; 
     
    199197 
    200198    public this(char[] server, char[] path, char[] username = "anonymous", 
    201                 char[] password = "anonymous@anonymous", uint port = 21, bool flat = false) 
     199                char[] password = "anonymous@anonymous", uint port = 21, 
     200                bool flat = false) 
    202201    in { 
    203202        assert(server != ""); 
     
    280279    } 
    281280 
    282     VfsFolders subset (char[] pattern)
     281    VfsFolders subset(char[] pattern)
    283282        return null; 
    284283    } 
     
    302301    body { 
    303302        toString_ = server; 
    304         name_ = name != "" ? path : server
     303        name_ = path
    305304        username_ = username; 
    306305        password_ = password; 
     
    507506    } 
    508507} 
     508 
     509debug(UnitTest){ 
     510    /* 
     511     *  
     512     */ 
     513 
     514    import tango.io.Stdout; 
     515    import tango.util.Convert; 
     516 
     517    int main() { 
     518         
     519        //variables 
     520         
     521        VfsFolder folder; 
     522        VfsFile file; 
     523        VfsFolders folders; 
     524        VfsFiles files; 
     525        VfsFolderEntry entry; 
     526        char[] toPrint; 
     527         
     528        //init code 
     529         
     530        entry = new FtpFolderEntry("ftp.digitalmars.com", ""); 
     531        Stdout("Inited entry.").newline.flush; 
     532        folder = entry.open(); 
     533        //folder = new FtpFolder("ftp.digitalmars.com", ""); 
     534        Stdout("Inited folder.").newline.flush; 
     535        folders = folder.tree(); 
     536        Stdout("Inited tree.").newline.flush; 
     537        file = folder.file("dmd.1.00.zip"); 
     538        Stdout("Inited file.").newline.flush; 
     539        files = folders.catalog("dmd"); 
     540        Stdout("Inited catalog.").newline.flush; 
     541        Stdout("Initialization Passed.").newline.newline.flush; 
     542 
     543        //print information gatherable from all of 
     544        //the variables 
     545         
     546        //entry 
     547        Stdout("Folder exists: ").flush; 
     548        toPrint = to!(char[])(entry.exists()); 
     549        Stdout(toPrint).newline.flush; 
     550         
     551        //folder 
     552        Stdout("Folder:").newline.flush; 
     553        toPrint = "\n\t writeable: " ~ to!(char[])(folder.writable()); 
     554        toPrint ~= "\n\t name: " ~ folder.name(); 
     555        toPrint ~= "\n\t path: " ~folder.toString(); 
     556        Stdout(toPrint).newline.flush; 
     557         
     558        //folders 
     559        Stdout("Folders: ").newline.flush; 
     560        toPrint = "\n\t #of Files: " ~ to!(char[])(folders.files()); 
     561        toPrint ~= "\n\t #of Folders: " ~ to!(char[])(folders.folders()); 
     562        toPrint ~= "\n\t Total Objects: " ~ to!(char[])(folders.entries()); 
     563        toPrint ~= "\n\t Folders Occupies Space: " ~ to!(char[])(folders.bytes()); 
     564        Stdout(toPrint).newline.flush; 
     565         
     566        //file 
     567        Stdout("File: ").newline.flush; 
     568        toPrint = "\n\t exists: " ~ to!(char[])(file.exists()); 
     569        toPrint ~= "\n\t size: " ~ to!(char[])(file.size()); 
     570        toPrint ~= "\n\t name: " ~ file.name(); 
     571        toPrint ~= "\n\t path: " ~ file.toString(); 
     572        Stdout(toPrint).newline.flush; 
     573         
     574        //files 
     575        Stdout("Files: ").newline.flush; 
     576        Stdout("\n\t Size sum: "); 
     577        Stdout(files.bytes()); 
     578        Stdout("\n\t #of Files: ").flush; 
     579        Stdout(files.files()).newline.flush; 
     580         
     581        return 0; 
     582    } 
     583 
     584}