int n_mirror(string *args, struct shell_state *sh) { struct afc_directory *dir; char *dirent; if (args[1] == "" ) { ifNotQuiet cout << "mirror: please specify local dir." << endl; return SHELL_CONTINUE; } string base = string(sh->remote_path); mkdir((args[1] + sh->remote_path).c_str()); if (AFCDirectoryOpen(sh->conn, (char*)base.c_str(), &dir)) { ifNotQuiet cout << "oops getdir " << base << endl; return SHELL_CONTINUE; } while (1) { int i = 2; char skip = 0; AFCDirectoryRead(0, dir, &dirent); if (!dirent) { break; } if( strcmp(dirent,".") == 0 || strcmp(dirent,"..") == 0 ) { continue; } string currentPhone = base + "/" + dirent; string currentLocal = args[1] + "/" + currentPhone; while (args[i] != "") { if (currentPhone.find(args[i]) != string::npos) { ifNotQuiet cout << "Skipping " << dirent << endl; skip = 1; break; } i++; } if (skip) { continue; } if (dirExists(sh->conn, (char*)currentPhone.c_str())) { mkdir(currentLocal.c_str()); sh->remote_path = currentPhone; n_mirror(args, sh); } else { string copyArgs[3]; copyArgs[0] = args[0]; copyArgs[1] = currentPhone; copyArgs[2] = currentLocal; ifNotQuiet cout << "mirror file " << currentPhone << " to " << currentLocal << endl; n_getfile(copyArgs, sh); } } return SHELL_CONTINUE; }