 |
Changeset 3388
- 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
| r3387 |
r3388 |
|
| 7 | 7 | |
|---|
| 8 | 8 | //fix flatness |
|---|
| 9 | | |
|---|
| 10 | 9 | module tango.io.vfs.FtpFolder; |
|---|
| 11 | 10 | |
|---|
| … | … | |
| 15 | 14 | import tango.io.Conduit; |
|---|
| 16 | 15 | import tango.text.Util; |
|---|
| | 16 | |
|---|
| | 17 | private 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 | } |
|---|
| 17 | 31 | |
|---|
| 18 | 32 | class FtpFolderEntry: VfsFolderEntry { |
|---|
| … | … | |
| 115 | 129 | ftp_ = new FTPConnection(); |
|---|
| 116 | 130 | ftp_.connect(toString_, username_, password_, port_); |
|---|
| 117 | | FtpFileInfo[] fis = ftp_.ls(name_); |
|---|
| | 131 | FtpFileInfo[] fis = getFiles(ftp_, name_); |
|---|
| 118 | 132 | ftp_.close(); |
|---|
| 119 | 133 | |
|---|
| … | … | |
| 149 | 163 | try { |
|---|
| 150 | 164 | 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; |
|---|
| 156 | 167 | } catch(Exception e) { |
|---|
| 157 | 168 | writeable_ = false; |
|---|
| … | … | |
| 223 | 234 | ftp_ = new FTPConnection(); |
|---|
| 224 | 235 | ftp_.connect(toString_, username_, password_, port_); |
|---|
| 225 | | FtpFileInfo[] fis = ftp_.ls(); |
|---|
| | 236 | FtpFileInfo[] fis = getFiles(ftp_); |
|---|
| 226 | 237 | ftp_.close(); |
|---|
| 227 | 238 | uint size; |
|---|
| … | … | |
| 238 | 249 | ftp_ = new FTPConnection(); |
|---|
| 239 | 250 | ftp_.connect(toString_, username_, password_, port_); |
|---|
| 240 | | FtpFileInfo[] fis = ftp_.ls(); |
|---|
| | 251 | FtpFileInfo[] fis = getFiles(ftp_); |
|---|
| 241 | 252 | ftp_.close(); |
|---|
| 242 | 253 | uint size; |
|---|
| 243 | 254 | |
|---|
| 244 | 255 | foreach(FtpFileInfo fi; fis) { |
|---|
| 245 | | if(fi.type != FtpFileType.unknown || fi.type != FtpFileType.file || fi.type != FtpFileType.other) |
|---|
| | 256 | if(fi.type == FtpFileType.dir) |
|---|
| 246 | 257 | size++; |
|---|
| 247 | 258 | } |
|---|
| … | … | |
| 257 | 268 | ftp_ = new FTPConnection(); |
|---|
| 258 | 269 | ftp_.connect(toString_, username_, password_, port_); |
|---|
| 259 | | FtpFileInfo[] fis = ftp_.ls(); |
|---|
| | 270 | FtpFileInfo[] fis = getFiles(ftp_); |
|---|
| 260 | 271 | ftp_.close(); |
|---|
| 261 | 272 | uint size; |
|---|
| … | … | |
| 463 | 474 | } |
|---|
| 464 | 475 | if(doFilter_) { |
|---|
| 465 | | FtpFileInfo[] infs = ftp_.ls(); |
|---|
| | 476 | FtpFileInfo[] infs = getFiles(ftp_); |
|---|
| 466 | 477 | FtpFileInfo[] toReturn; |
|---|
| 467 | 478 | if(useFilter_) { |
|---|
| … | … | |
| 491 | 502 | return toReturn; |
|---|
| 492 | 503 | } else |
|---|
| 493 | | return ftp_.ls(); |
|---|
| | 504 | return getFiles(ftp_); |
|---|
| 494 | 505 | } |
|---|
| 495 | 506 | |
|---|
| … | … | |
| 507 | 518 | } |
|---|
| 508 | 519 | |
|---|
| 509 | | debug(UnitTest){ |
|---|
| | 520 | debug(UnitTest) { |
|---|
| 510 | 521 | /* |
|---|
| 511 | 522 | * |
|---|
| 512 | 523 | */ |
|---|
| 513 | 524 | |
|---|
| | 525 | import tango.io.vfs.model.Vfs; |
|---|
| | 526 | import FtpFolder; |
|---|
| | 527 | import tango.net.ftp.FtpClient; |
|---|
| 514 | 528 | import tango.io.Stdout; |
|---|
| 515 | 529 | import tango.util.Convert; |
|---|
| 516 | 530 | |
|---|
| 517 | 531 | int main() { |
|---|
| 518 | | |
|---|
| | 532 | |
|---|
| 519 | 533 | //variables |
|---|
| 520 | | |
|---|
| | 534 | |
|---|
| 521 | 535 | VfsFolder folder; |
|---|
| 522 | 536 | VfsFile file; |
|---|
| … | … | |
| 525 | 539 | VfsFolderEntry entry; |
|---|
| 526 | 540 | char[] toPrint; |
|---|
| 527 | | |
|---|
| | 541 | |
|---|
| 528 | 542 | //init code |
|---|
| 529 | | |
|---|
| 530 | | entry = new FtpFolderEntry("ftp.digitalmars.com", ""); |
|---|
| | 543 | |
|---|
| | 544 | entry = new FtpFolderEntry("127.0.0.1", "", "lmartin92", "asunset!", 21); |
|---|
| 531 | 545 | Stdout("Inited entry.").newline.flush; |
|---|
| 532 | 546 | folder = entry.open(); |
|---|
| 533 | | //folder = new FtpFolder("ftp.digitalmars.com", ""); |
|---|
| | 547 | //folder = new FtpFolder("ftp.digitalmars.com", ""); |
|---|
| 534 | 548 | Stdout("Inited folder.").newline.flush; |
|---|
| 535 | 549 | folders = folder.tree(); |
|---|
| 536 | 550 | Stdout("Inited tree.").newline.flush; |
|---|
| 537 | | file = folder.file("dmd.1.00.zip"); |
|---|
| | 551 | file = folder.file("client.exe"); |
|---|
| 538 | 552 | Stdout("Inited file.").newline.flush; |
|---|
| 539 | | files = folders.catalog("dmd"); |
|---|
| | 553 | files = folders.catalog("cli"); |
|---|
| 540 | 554 | Stdout("Inited catalog.").newline.flush; |
|---|
| 541 | 555 | Stdout("Initialization Passed.").newline.newline.flush; |
|---|
| … | … | |
| 543 | 557 | //print information gatherable from all of |
|---|
| 544 | 558 | //the variables |
|---|
| 545 | | |
|---|
| | 559 | |
|---|
| 546 | 560 | //entry |
|---|
| 547 | 561 | Stdout("Folder exists: ").flush; |
|---|
| 548 | 562 | toPrint = to!(char[])(entry.exists()); |
|---|
| 549 | 563 | Stdout(toPrint).newline.flush; |
|---|
| 550 | | |
|---|
| | 564 | |
|---|
| 551 | 565 | //folder |
|---|
| 552 | 566 | Stdout("Folder:").newline.flush; |
|---|
| 553 | 567 | toPrint = "\n\t writeable: " ~ to!(char[])(folder.writable()); |
|---|
| 554 | 568 | toPrint ~= "\n\t name: " ~ folder.name(); |
|---|
| 555 | | toPrint ~= "\n\t path: " ~folder.toString(); |
|---|
| | 569 | toPrint ~= "\n\t path: " ~ folder.toString(); |
|---|
| 556 | 570 | Stdout(toPrint).newline.flush; |
|---|
| 557 | | |
|---|
| | 571 | |
|---|
| 558 | 572 | //folders |
|---|
| 559 | 573 | Stdout("Folders: ").newline.flush; |
|---|
| … | … | |
| 561 | 575 | toPrint ~= "\n\t #of Folders: " ~ to!(char[])(folders.folders()); |
|---|
| 562 | 576 | 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()); |
|---|
| 564 | 579 | Stdout(toPrint).newline.flush; |
|---|
| 565 | | |
|---|
| | 580 | |
|---|
| 566 | 581 | //file |
|---|
| 567 | 582 | Stdout("File: ").newline.flush; |
|---|
| … | … | |
| 571 | 586 | toPrint ~= "\n\t path: " ~ file.toString(); |
|---|
| 572 | 587 | Stdout(toPrint).newline.flush; |
|---|
| 573 | | |
|---|
| | 588 | |
|---|
| 574 | 589 | //files |
|---|
| 575 | 590 | Stdout("Files: ").newline.flush; |
|---|
| … | … | |
| 578 | 593 | Stdout("\n\t #of Files: ").flush; |
|---|
| 579 | 594 | Stdout(files.files()).newline.flush; |
|---|
| 580 | | |
|---|
| | 595 | |
|---|
| 581 | 596 | return 0; |
|---|
| 582 | 597 | } |
|---|
| 583 | | |
|---|
| 584 | | } |
|---|
| | 598 | } |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic