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

Changeset 3484

Show
Ignore:
Timestamp:
05/04/08 17:02:48 (7 months ago)
Author:
lmartin92
Message:

I fixed a OutputStream?.copy() problem in FtpClient?.d and it still works perfectly. Old code may not even be removed, probably just commented out. Needs comments for all methods.
I have worked a little on FtpFolder? today and have made parts of it where it would download do this: rather than look to see if it had it and if not then store it. To get updated information one would need to recreate the object or something with the same parameters. I'll work on a way that will update it maybe every 10 accesses or something or know if there have been any Files written to the server or something.

Files:

Legend:

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

    r3388 r3484  
    1 /* 
    2  * Author: Lester L. Martin II 
    3  * Copyright(c) Lester L. Martin II 2008 All rights reserved 
    4  * Liscense: $(BSD) 
    5  *  
    6  */ 
    7  
    8 //fix flatness 
    9 module tango.io.vfs.FtpFolder; 
    10  
    11 import tango.net.ftp.FtpClient; 
    12 import tango.io.vfs.model.Vfs; 
    13 import tango.io.vfs.FileFolder; 
    14 import tango.io.Conduit; 
    15 import tango.text.Util; 
     1module tango.io.vfs.FtpFolder; 
     2 
     3private { 
     4    import tango.net.ftp.FtpClient; 
     5    import tango.io.vfs.model.Vfs; 
     6    import tango.io.vfs.FileFolder; 
     7    import tango.io.Conduit; 
     8    import tango.text.Util; 
     9
    1610 
    1711private FtpFileInfo[] getFiles(FTPConnection ftp, char[] path = "") { 
     
    4135        assert(server != ""); 
    4236    } 
    43     out { 
    44         assert(server != ""); 
    45     } 
    4637    body { 
    4738        toString_ = server; 
     
    5748 
    5849    VfsFolder create() { 
    59         if(exists()) { 
    60             ftp_.close(); 
    61             throw new Exception("This FTP Directory is already in existence."); 
    62         } else { 
    63             ftp_.close(); 
    64             ftp_ = new FTPConnection(); 
    65             ftp_.connect(toString_, username_, password_, port_); 
    66             ftp_.mkdir(name_); 
    67             ftp_.close(); 
    68         } 
     50        ftp_ = new FTPConnection(); 
     51        ftp_.connect(toString_, username_, password_, port_); 
     52        ftp_.mkdir(name_); 
     53        ftp_.close(); 
    6954        return new FtpFolder(toString_, name_, username_, password_, port_); 
    7055    } 
     
    7358        ftp_ = new FTPConnection(); 
    7459        ftp_.connect(toString_, username_, password_, port_); 
    75         return name_ == "" ? true : (ftp_.exist(name_) == 2 ? true : false); 
     60        switch(ftp_.exist(name_ != "" ? name_ : toString_)) { 
     61        case 0: 
     62            ftp_.close(); 
     63            return false; 
     64            break; 
     65        case 1: 
     66            ftp_.close(); 
     67            return false; 
     68            break; 
     69        case 2: 
     70            ftp_.close(); 
     71            return true; 
     72            break; 
     73        default: 
     74            ftp_.close(); 
     75        return false; 
     76        break; 
     77        } 
     78        return false; 
    7679    } 
    7780} 
     
    8285    char[] toString_, name_, username_, password_; 
    8386    uint port_; 
    84     bool writeable_, writeableSet_; 
     87    bool writeable_, writeableSet_, fileInfosSet_; 
     88    FtpFileInfo[] fileInfos_; 
    8589 
    8690    public this(char[] server, char[] path, char[] username = "anonymous", 
     
    109113 
    110114    VfsFile file(char[] path) { 
    111         return new FtpFile(toString_ ~ name_, path, username_, password_, port_); 
     115        return new FtpFile(toString_ ~ name_, '/' ~ path, username_, password_, port_); 
    112116    } 
    113117 
    114118    VfsFolderEntry folder(char[] path) { 
    115         return new FtpFolderEntry(toString_, name_, username_, password_, port_); 
     119        return new FtpFolderEntry(toString_, '/' ~ path, username_, password_, port_); 
    116120    } 
    117121 
     
    127131 
    128132    int opApply(int delegate(inout VfsFolder) dg) { 
    129         ftp_ = new FTPConnection(); 
    130         ftp_.connect(toString_, username_, password_, port_); 
    131         FtpFileInfo[] fis = getFiles(ftp_, name_); 
    132         ftp_.close(); 
     133        if(!fileInfosSet_) { 
     134            ftp_ = new FTPConnection(); 
     135            ftp_.connect(toString_, username_, password_, port_); 
     136            fileInfos_ = getFiles(ftp_, name_); 
     137            ftp_.close(); 
     138            fileInfosSet_ = true; 
     139        } 
    133140 
    134141        int result; 
    135142 
    136         foreach(FtpFileInfo fi; fis) { 
     143        foreach(FtpFileInfo fi; fileInfos_) { 
    137144            if(fi.type == FtpFileType.dir) { 
    138145                VfsFolder x = new FtpFolder(toString_, fi.name, username_, 
     
    163170            try { 
    164171                ftp_.mkdir("diw"); 
    165                 ftp_.rm("diw"); 
     172                ftp_.rm("/diw"); 
    166173                writeable_ = true; 
    167174            } catch(Exception e) { 
     
    175182 
    176183    VfsFolder close(bool commit = true) { 
    177        ftp_.close(); 
     184        ftp_.close(); 
    178185        return new FtpFolder(toString_, name_, username_, password_, port_); 
    179186    } 
    180187 
    181188    void verify(VfsFolder folder, bool mounting) { 
    182        return null; 
     189        return null; 
    183190    } 
    184191} 
     
    186193class FtpFolders: VfsFolders { 
    187194 
    188    FTPConnection ftp_; 
     195    FTPConnection ftp_; 
    189196    char[] toString_, name_, username_, password_; 
    190     uint port_; 
    191     bool flat_; 
     197    uint port_ , fileNum_, folderNum_; 
     198    ulong bytes_; 
     199    bool flat_, fileInfosSet_, fileNumSet_, folderNumSet_, bytesSet_; 
     200    FtpFileInfo[] fileInfos_; 
    192201 
    193202    public this(char[] server, char[] path, char[] username = "anonymous", 
    194                 char[] password = "anonymous@anonymous", uint port = 21) 
     203           char[] password = "anonymous@anonymous", uint port = 21) 
    195204    in { 
    196205        assert(server != ""); 
     
    208217 
    209218    public this(char[] server, char[] path, char[] username = "anonymous", 
    210                 char[] password = "anonymous@anonymous", uint port = 21, 
    211                 bool flat = false) 
     219           char[] password = "anonymous@anonymous", uint port = 21, 
     220           bool flat = false) 
    212221    in { 
    213222        assert(server != ""); 
     
    226235 
    227236    int opApply(int delegate(inout VfsFolder) dg) { 
    228         FtpFolder ftp = new FtpFolder(toString_, name_, username_, password_, 
    229             port_); 
    230         return ftp.opApply(dg); 
     237        if(!fileInfosSet_) { 
     238            ftp_ = new FTPConnection(); 
     239            ftp_.connect(toString_, username_, password_, port_); 
     240            fileInfos_ = getFiles(ftp_, name_); 
     241            ftp_.close(); 
     242            fileInfosSet_ = true; 
     243        } 
     244 
     245        int result; 
     246 
     247        foreach(FtpFileInfo fi; fileInfos_) { 
     248            if(fi.type == FtpFileType.dir) { 
     249                VfsFolder x = new FtpFolder(toString_, fi.name, username_, 
     250                        password_, port_); 
     251                if((result = dg(x)) != 0) 
     252                    break; 
     253            } 
     254        } 
     255 
     256        return result; 
    231257    } 
    232258 
    233259    uint files() { 
    234         ftp_ = new FTPConnection(); 
    235         ftp_.connect(toString_, username_, password_, port_); 
    236         FtpFileInfo[] fis = getFiles(ftp_); 
    237         ftp_.close(); 
    238         uint size; 
    239  
    240         foreach(FtpFileInfo fi; fis) { 
    241             if(fi.type == FtpFileType.unknown || fi.type == FtpFileType.file || fi.type == FtpFileType.other) 
     260        if(!fileNumSet_) 
     261        { 
     262            ftp_ = new FTPConnection(); 
     263            ftp_.connect(toString_, username_, password_, port_); 
     264            FtpFileInfo[] fis = getFiles(ftp_); 
     265            ftp_.close(); 
     266            uint size; 
     267 
     268            foreach(FtpFileInfo fi; fis) { 
     269                if(fi.type == FtpFileType.unknown || fi.type == FtpFileType.file || fi.type == FtpFileType.other) 
    242270                size++; 
    243         } 
    244  
    245         return size; 
     271            } 
     272 
     273            fileNum_ = size; 
     274            fileNumSet_ = true; 
     275        } 
     276         
     277        return fileNum_; 
    246278    } 
    247279 
    248280    uint folders() { 
    249         ftp_ = new FTPConnection(); 
    250         ftp_.connect(toString_, username_, password_, port_); 
    251         FtpFileInfo[] fis = getFiles(ftp_); 
    252         ftp_.close(); 
    253         uint size; 
    254  
    255         foreach(FtpFileInfo fi; fis) { 
    256             if(fi.type == FtpFileType.dir) 
    257                 size++; 
    258         } 
    259  
    260         return size; 
     281        if(!folderNumSet_) { 
     282            uint size = 0; 
     283            if(!flat_) { 
     284                ftp_ = new FTPConnection(); 
     285                ftp_.connect(toString_, username_, password_, port_); 
     286                FtpFileInfo[] fis = getFiles(ftp_); 
     287                ftp_.close(); 
     288 
     289                foreach(FtpFileInfo fi; fis) { 
     290                    if(fi.type == FtpFileType.dir) 
     291                        size++; 
     292                } 
     293            } 
     294            folderNum_ = size; 
     295            folderNumSet_ = true; 
     296        } 
     297 
     298        return folderNum_; 
    261299    } 
    262300 
    263301    uint entries() { 
    264        return files + folders; 
     302        return files + folders; 
    265303    } 
    266304 
    267305    ulong bytes() { 
    268         ftp_ = new FTPConnection(); 
    269         ftp_.connect(toString_, username_, password_, port_); 
    270         FtpFileInfo[] fis = getFiles(ftp_); 
    271         ftp_.close(); 
    272         uint size; 
    273  
    274         foreach(FtpFileInfo fi; fis) { 
    275             if(fi.type == FtpFileType.unknown || fi.type == FtpFileType.file || fi.type == FtpFileType.other) 
    276                 size += fi.size; 
    277         } 
    278  
    279         return size; 
     306        if(!bytesSet_) { 
     307            ftp_ = new FTPConnection(); 
     308            ftp_.connect(toString_, username_, password_, port_); 
     309            FtpFileInfo[] fis = getFiles(ftp_); 
     310            ftp_.close(); 
     311            uint size; 
     312 
     313            foreach(FtpFileInfo fi; fis) { 
     314                if(fi.type == FtpFileType.unknown || fi.type == FtpFileType.file || fi.type == FtpFileType.other) 
     315                    size += fi.size; 
     316            } 
     317 
     318            bytes_ = size; 
     319            bytesSet_ = true; 
     320        } 
     321 
     322        return bytesSet_; 
     323    } 
     324 
     325    VfsFolders subset(char[] pattern) { 
     326        //to be done 
    280327    } 
    281328 
    282329    VfsFiles catalog(char[] pattern) { 
    283        return new FtpFiles(toString_, name_, username_, password_, port_, 
    284             pattern); 
     330        return new FtpFiles(toString_, name_, username_, password_, port_, 
     331               pattern); 
    285332    } 
    286333 
    287334    VfsFiles catalog(VfsFilter filter = null) { 
    288         return new FtpFiles(toString_, name_, username_, password_, port_, 
    289             filter); 
    290     } 
    291  
    292     VfsFolders subset(char[] pattern) { 
    293         return null; 
     335        return new FtpFiles(toString_, name_, username_, password_, port_, 
     336                filter); 
    294337    } 
    295338} 
     
    297340class FtpFile: VfsFile { 
    298341 
    299     FTPConnection ftp_; 
    300     char[] toString_, name_, username_, password_; 
    301     uint port_; 
    302     bool writeable_, writeableSet_; 
    303  
    304     public this(char[] server, char[] path, char[] username = "anonymous", 
    305                 char[] password = "anonymous@anonymous", uint port = 21) 
    306     in { 
    307         assert(server != ""); 
    308     } 
    309     out { 
    310         assert(server != ""); 
    311     } 
    312     body { 
    313         toString_ = server; 
    314         name_ = path; 
    315         username_ = username; 
    316         password_ = password; 
    317         port_ = port; 
    318     } 
    319  
    320342    char[] name() { 
    321         return name_; 
    322343    } 
    323344 
    324345    char[] toString() { 
    325         return toString_ ~ '/' ~ name_; 
    326346    } 
    327347 
    328348    bool exists() { 
    329         ftp_ = new FTPConnection(); 
    330         ftp_.connect(toString_, username_, password_, port_); 
    331         bool result = ftp_.exist(name_) == 1 ? true : false; 
    332         ftp_.close(); 
    333         return result; 
    334349    } 
    335350 
    336351    ulong size() { 
    337         ulong result = 0; 
    338         if(exists()) { 
    339             ftp_ = new FTPConnection(); 
    340             ftp_.connect(toString_, username_, password_, port_); 
    341             result = ftp_.getFileInfo(name_).size; 
    342             ftp_.close(); 
    343         } 
    344         return result; 
    345352    } 
    346353 
    347354    VfsFile copy(VfsFile source) { 
    348         void[] dest; 
    349         source.input.read(dest); 
    350         output.write(dest); 
    351         return new FtpFile(toString_, name_, username_, password_, port_); 
    352355    } 
    353356 
    354357    VfsFile move(VfsFile source) { 
    355         copy(source); 
    356         source.remove; 
    357         return new FtpFile(toString_, name_, username_, password_, port_); 
    358358    } 
    359359 
    360360    VfsFile create() { 
    361         VfsFolder f = new FileFolder(""); 
    362         VfsFile ff = f.file("/NF.NF"); 
    363         ftp_ = new FTPConnection(); 
    364         ftp_.connect(toString_, username_, password_, port_); 
    365         ftp_.put(name_, ff.input); 
    366         ftp_.close(); 
    367         ff.remove(); 
    368         return new FtpFile(toString_, name_, username_, password_, port_); 
    369361    } 
    370362 
    371363    VfsFile create(InputStream stream) { 
    372         ftp_ = new FTPConnection(); 
    373         ftp_.connect(toString_, username_, password_, port_); 
    374         ftp_.put(name_, stream); 
    375         ftp_.close(); 
    376         return new FtpFile(toString_, name_, username_, password_, port_); 
    377364    } 
    378365 
    379366    VfsFile remove() { 
    380         ftp_ = new FTPConnection(); 
    381         ftp_.connect(toString_, username_, password_, port_); 
    382         ftp_.del(name_); 
    383         return new FtpFile(toString_, name_, username_, password_, port_); 
    384367    } 
    385368 
    386369    InputStream input() { 
    387         ftp_ = new FTPConnection(); 
    388         ftp_.connect(toString_, username_, password_, port_); 
    389         InputStream input = ftp_.input; 
    390         prepareInputStream(ftp_, input, FtpCommand.RETR, ["", name_]); 
    391         ftp_.close(); 
    392         return input; 
    393370    } 
    394371 
    395372    OutputStream output() { 
    396         ftp_ = new FTPConnection(); 
    397         ftp_.connect(toString_, username_, password_, port_); 
    398         OutputStream output = ftp_.output; 
    399         prepareOutputStream(ftp_, output, FtpCommand.STOR, ["", name_]); 
    400         ftp_.close(); 
    401         return output; 
    402373    } 
    403374 
    404375    VfsFile dup() { 
    405         return new FtpFile(toString_, name_, username_, password_, port_); 
    406376    } 
    407377} 
     
    409379class FtpFiles: VfsFiles { 
    410380 
    411     FTPConnection ftp_; 
    412     char[] toString_, name_, username_, password_; 
    413     uint port_; 
    414     bool writeable_, writeableSet_; 
    415     char[] filter_; 
    416     VfsFilter ffilter_; 
    417     bool useFilter_ = false; 
    418     bool doFilter_ = true; 
    419  
    420     public this(char[] server, char[] path, char[] username = "anonymous", 
    421                 char[] password = "anonymous@anonymous", uint port = 21, 
    422                 char[] filtPattern = "") 
    423     in { 
    424         assert(server != ""); 
    425     } 
    426     out { 
    427         assert(server != ""); 
    428     } 
    429     body { 
    430         toString_ = server; 
    431         name_ = path != "" ? path : server; 
    432         username_ = username; 
    433         password_ = password; 
    434         port_ = port; 
    435         filter_ = filtPattern; 
    436  
    437         useFilter_ = true; 
    438     } 
    439  
    440     public this(char[] server, char[] path, char[] username = "anonymous", 
    441                 char[] password = "anonymous@anonymous", uint port = 21, 
    442                 VfsFilter filter = null) 
    443     in { 
    444         assert(server != ""); 
    445     } 
    446     out { 
    447         assert(server != ""); 
    448     } 
    449     body { 
    450         toString_ = server; 
    451         name_ = path != "" ? path : server; 
    452         username_ = username; 
    453         password_ = password; 
    454         port_ = port; 
    455         ffilter_ = filter; 
    456     } 
    457  
    458381    int opApply(int delegate(inout VfsFile) dg) { 
    459         int result; 
    460         foreach(FtpFileInfo inf; getFileInfo()) { 
    461             VfsFile x = new FtpFile(toString_, inf.name, username_, password_, 
    462                 port_); 
    463             if((result = dg(x)) != 0) 
    464                 break; 
    465         } 
    466         return result; 
    467     } 
    468  
    469     FtpFileInfo[] getFileInfo() { 
    470         ftp_ = new FTPConnection(); 
    471         ftp_.connect(toString_, username_, password_, port_); 
    472         scope(exit) { 
    473             ftp_.close(); 
    474         } 
    475         if(doFilter_) { 
    476             FtpFileInfo[] infs = getFiles(ftp_); 
    477             FtpFileInfo[] toReturn; 
    478             if(useFilter_) { 
    479                 foreach(FtpFileInfo inf; infs) { 
    480                     if(containsPattern(inf.name, filter_)) { 
    481                         toReturn ~= inf; 
    482                     } 
    483                 } 
    484             } else { 
    485                 VfsFilterInfo[] toUse; 
    486                 foreach(FtpFileInfo inf; infs) { 
    487                     VfsFilterInfo temp; 
    488                     temp.name = inf.name; 
    489                     temp.folder = false; 
    490                     temp.path = toString_ ~ temp.name; 
    491                     temp.bytes = inf.size; 
    492                     toUse ~= temp; 
    493                 } 
    494                 foreach(VfsFilterInfo inf; toUse) { 
    495                     if(ffilter_(&inf)) { 
    496                         FtpFileInfo temp; 
    497                         temp.name = inf.name; 
    498                         toReturn ~= temp; 
    499                     } 
    500                 } 
    501             } 
    502             return toReturn; 
    503         } else 
    504             return getFiles(ftp_); 
    505382    } 
    506383 
    507384    uint files() { 
    508         return getFileInfo().length; 
    509385    } 
    510386 
    511387    ulong bytes() { 
    512         ulong result; 
    513         foreach(FtpFileInfo inf; getFileInfo()) { 
    514             result += inf.size; 
    515         } 
    516         return result; 
    517     } 
    518 
    519  
    520 debug(UnitTest) { 
    521     /* 
    522      *  
    523      */ 
    524  
    525     import tango.io.vfs.model.Vfs; 
    526     import FtpFolder; 
    527     import tango.net.ftp.FtpClient; 
    528     import tango.io.Stdout; 
    529     import tango.util.Convert; 
    530  
    531     int main() { 
    532  
    533         //variables 
    534  
    535         VfsFolder folder; 
    536         VfsFile file; 
    537         VfsFolders folders; 
    538         VfsFiles files; 
    539         VfsFolderEntry entry; 
    540         char[] toPrint; 
    541  
    542         //init code 
    543  
    544         entry = new FtpFolderEntry("127.0.0.1", "", "lmartin92", "asunset!", 21); 
    545         Stdout("Inited entry.").newline.flush; 
    546         folder = entry.open(); 
    547         //folder = new FtpFolder("ftp.digitalmars.com", ""); 
    548         Stdout("Inited folder.").newline.flush; 
    549         folders = folder.tree(); 
    550         Stdout("Inited tree.").newline.flush; 
    551         file = folder.file("client.exe"); 
    552         Stdout("Inited file.").newline.flush; 
    553         files = folders.catalog("cli"); 
    554         Stdout("Inited catalog.").newline.flush; 
    555         Stdout("Initialization Passed.").newline.newline.flush; 
    556  
    557         //print information gatherable from all of 
    558         //the variables 
    559  
    560         //entry 
    561         Stdout("Folder exists: ").flush; 
    562         toPrint = to!(char[])(entry.exists()); 
    563         Stdout(toPrint).newline.flush; 
    564  
    565         //folder 
    566         Stdout("Folder:").newline.flush; 
    567         toPrint = "\n\t writeable: " ~ to!(char[])(folder.writable()); 
    568         toPrint ~= "\n\t name: " ~ folder.name(); 
    569         toPrint ~= "\n\t path: " ~ folder.toString(); 
    570         Stdout(toPrint).newline.flush; 
    571  
    572         //folders 
    573         Stdout("Folders: ").newline.flush; 
    574         toPrint = "\n\t #of Files: " ~ to!(char[])(folders.files()); 
    575         toPrint ~= "\n\t #of Folders: " ~ to!(char[])(folders.folders()); 
    576         toPrint ~= "\n\t Total Objects: " ~ to!(char[])(folders.entries()); 
    577         toPrint ~= "\n\t Folders Occupies Space: " ~ to!(char[])( 
    578                 folders.bytes()); 
    579         Stdout(toPrint).newline.flush; 
    580  
    581         //file 
    582         Stdout("File: ").newline.flush; 
    583         toPrint = "\n\t exists: " ~ to!(char[])(file.exists()); 
    584         toPrint ~= "\n\t size: " ~ to!(char[])(file.size()); 
    585         toPrint ~= "\n\t name: " ~ file.name(); 
    586         toPrint ~= "\n\t path: " ~ file.toString(); 
    587         Stdout(toPrint).newline.flush; 
    588  
    589         //files 
    590         Stdout("Files: ").newline.flush; 
    591         Stdout("\n\t Size sum: "); 
    592         Stdout(files.bytes()); 
    593         Stdout("\n\t #of Files: ").flush; 
    594         Stdout(files.files()).newline.flush; 
    595  
    596         return 0; 
    597     } 
    598 
     388    } 
     389
  • branches/lmartin/ftp/tango/net/ftp/FtpClient.d

    r3481 r3484  
    3232    debug(UnitTest) { 
    3333        import tango.io.Stdout; 
    34         import tango.io.FileSystem; 
     34        import tango.io.FileSystem; 
     35        import tango.core.thread; 
     36        import tango.io.stream.SnoopStream; 
    3537    } 
    3638} 
     
    326328 
    327329    public void close() { 
    328         //make sure no open data connection and if open data connection then kill 
    329         if(dataSocket_ !is null) 
    330             this.finishDataCommand(dataSocket_); 
     330       //make sure no open data connection and if open data connection then kill 
     331       if(dataSocket_ !is null) 
     332           this.finishDataCommand(dataSocket_); 
    331333        if(socket_ !is null) { 
    332334            try { 
     
    673675    /// Returns:             the data socket or a listener 
    674676    protected SocketConduit getDataSocket() { 
    675         //make sure no open data connection and if open data connection then kill 
    676         if(dataSocket_ !is null) 
    677             this.finishDataCommand(dataSocket_); 
    678          
     677       //make sure no open data connection and if open data connection then kill 
     678       if(dataSocket_ !is null) 
     679           this.finishDataCommand(dataSocket_); 
     680 
    679681        // What type are we using? 
    680682        switch(this.inf_.type) { 
     
    892894 
    893895        // We shouldn't get a 250 in STREAM mode. 
    894         FtpResponse r = readResponse(); 
    895         if(!(r.code == "226" || r.code == "420")) 
    896             exception("Bad finish"); 
    897              
     896       FtpResponse r = readResponse(); 
     897       if(!(r.code == "226" || r.code == "420")) 
     898           exception("Bad finish"); 
     899 
    898900    } 
    899901 
     
    15361538    } 
    15371539 
    1538     public InputStream input(char[] path)
    1539         dataSocket_ = this.processDataCommand("RETR", path); 
    1540         return dataSocket_; 
    1541    
    1542  
    1543     public OutputStream output(char[] path)
    1544         dataSocket_ = this.processDataCommand("STOR", path); 
    1545         return dataSocket_; 
    1546    
     1540   public InputStream input(char[] path)
     1541       dataSocket_ = this.processDataCommand("RETR", path); 
     1542       return dataSocket_; 
     1543   
     1544 
     1545   public OutputStream output(char[] path)
     1546       dataSocket_ = this.processDataCommand("STOR", path); 
     1547       return dataSocket_; 
     1548   
    15471549 
    15481550} 
     
    15541556 
    15551557    void main() { 
    1556         auto layout = new Locale; 
    1557         FileSystem.setDirectory(FileSystem.toAbsolute("Z:/")); 
    1558         auto fp = new FilePath(FileSystem.toAbsolute("Z:/")); 
     1558 
     1559            auto layout = new Locale; 
     1560            FileSystem.setDirectory(FileSystem.toAbsolute("Z:/")); 
     1561            auto fp = new FilePath(FileSystem.toAbsolute("Z:/")); 
     1562 
     1563            Stdout("Testing the new parts in FtpClient.d").newline.flush; 
     1564            FTPConnection conn = new FTPConnection("localhost", "me", "pass", 21); 
     1565            Stdout("Connecting works!").newline.flush; 
     1566 
     1567            Stdout("Making directory SS.").newline.flush; 
     1568            conn.mkdir("/SS"); 
     1569 
     1570            Stdout("Setting current directory to SS.").newline.flush; 
     1571            conn.cd("/SS"); 
     1572 
     1573            Stdout("Setting current directory to parent directory.").newline.flush; 
     1574            conn.cdup(); 
     1575 
     1576            Stdout("Removing directory SS.").newline.flush; 
     1577            conn.rm("/SS"); 
     1578 
     1579            Stdout("Checking for the existence of a file.").newline.flush; 
     1580            if(conn.exist("ServingSchedule.tif")) { 
     1581                Stdout("File exists.").newline.flush; 
     1582                Stdout("Getting size of file.").newline.flush; 
     1583                long size = conn.size("ServingSchedule.tif"); 
     1584                Stdout("The size of the file is: "); 
     1585                Stdout(size).newline.flush; 
     1586                Stdout("Renaming the file to No.").newline.flush; 
     1587                conn.rename("ServingSchedule.tif", "No"); 
     1588                Stdout("Getting the mod date.").newline.flush; 
     1589                Time modified = conn.modified("No"); 
     1590                Stdout("The file was modified: "); 
     1591                Stdout(layout("{:ddd, dd MMMM yyyy HH:mm:ss z}", modified)).newline.flush; 
     1592                Stdout("Deleting the file No.").newline.flush; 
     1593                conn.del("No"); 
     1594            } else 
     1595                Stdout("The file does not exist.").newline.flush; 
     1596 
     1597            Stdout("Listing content.").newline.flush; 
     1598            FtpFileInfo[] infs = conn.ls(); 
     1599            foreach(FtpFileInfo inf; infs) { 
     1600                Stdout(inf.name).newline.flush; 
     1601            } 
     1602 
     1603            Stdout("Now getting a file and writing it to a place.").newline.flush; 
     1604            conn.get("/Backup/ServingSchedule.tif", "/newFile.whatever"); 
     1605 
     1606            Stdout("Now putting a file to the server.").newline.flush; 
     1607            conn.put("ServingSchedule.tif", "/newFile.whatever"); 
     1608 
     1609             
     1610 
     1611            Stdout("Testing input.").newline.flush; 
     1612            FileConduit fcon = new FileConduit("Z:/whatever", 
     1613                FileConduit.ReadWriteCreate); 
     1614            fcon.copy(new SnoopInput(conn.input("/Backup/ServingSchedule.tif"))); 
     1615 
     1616            fcon.close(); 
     1617            fcon = new FileConduit("Z:/whatever", FileConduit.ReadExisting); 
     1618            Stdout("Testing output.").newline.flush; 
     1619            auto os = conn.output("/ServingSchedule.tif"); 
     1620            os.copy(new SnoopInput(fcon));    
    15591621         
    1560         Stdout("Testing the new parts in FtpClient.d").newline.flush; 
    1561         FTPConnection conn = new FTPConnection("localhost", "me", "pass", 21); 
    1562         Stdout("Connecting works!").newline.flush; 
    1563          
    1564         Stdout("Making directory SS.").newline.flush; 
    1565         conn.mkdir("/SS"); 
    1566          
    1567         Stdout("Setting current directory to SS.").newline.flush; 
    1568         conn.cd("/SS"); 
    1569          
    1570         Stdout("Setting current directory to parent directory.").newline.flush; 
    1571         conn.cdup(); 
    1572          
    1573         Stdout("Removing directory SS.").newline.flush; 
    1574         conn.rm("/SS"); 
    1575          
    1576         Stdout("Checking for the existence of a file.").newline.flush; 
    1577         if(conn.exist("ServingSchedule.tif")) { 
    1578             Stdout("File exists.").newline.flush; 
    1579             Stdout("Getting size of file.").newline.flush; 
    1580             long size = conn.size("ServingSchedule.tif"); 
    1581             Stdout("The size of the file is: "); 
    1582             Stdout(size).newline.flush; 
    1583             Stdout("Renaming the file to No.").newline.flush; 
    1584             conn.rename("ServingSchedule.tif", "No"); 
    1585             Stdout("Getting the mod date.").newline.flush; 
    1586             Time modified = conn.modified("No"); 
    1587             Stdout("The file was modified: "); 
    1588             Stdout(layout("{:ddd, dd MMMM yyyy HH:mm:ss z}", modified)).newline.flush; 
    1589             Stdout("Deleting the file No.").newline.flush; 
    1590             conn.del("No"); 
    1591         } else 
    1592             Stdout("The file does not exist.").newline.flush; 
    1593              
    1594         Stdout("Listing content.").newline.flush; 
    1595         FtpFileInfo[] infs = conn.ls(); 
    1596         foreach(FtpFileInfo inf; infs) { 
    1597             Stdout(inf.name).newline.flush; 
    1598         } 
    1599          
    1600         Stdout("Now getting a file and writing it to a place.").newline.flush; 
    1601         conn.get("/Backup/ServingSchedule.tif", "/newFile.whatever"); 
    1602          
    1603         Stdout("Now putting a file to the server.").newline.flush; 
    1604         conn.put("ServingSchedule.tif", "/newFile.whatever"); 
    1605  
    1606         Stdout("Testing input.").newline.flush; 
    1607         FileConduit fcon = new FileConduit("Z:/whatever", FileConduit.ReadWriteCreate); 
    1608         fcon.copy(conn.input("/Backup/ServingSchedule.tif")); 
    1609              
    1610         Stdout("Testing output.").newline.flush; 
    1611         OutputStream os = conn.output("ServingSchedule.tif"); 
    1612         os.copy(fcon.input()); 
    1613          
    1614         conn.close(); 
    1615         fcon.close(); 
    1616         fp = fp.file("/newFile.whatever"); 
    1617         fp.remove(); 
    1618         Stdout("Finished.").newline.flush; 
    1619     } 
     1622            os.close; 
     1623            conn.close(); 
     1624            fcon.close(); 
     1625            fp = fp.file("/newFile.whatever"); 
     1626            fp.remove(); 
     1627            Stdout("Finished.").newline.flush; 
     1628        
     1629    } 
    16201630}