public List<IFileEntry> List() { try { ListFolderResult lfr = dbx.ListFiles(m_path); List<IFileEntry> list = new List<IFileEntry>(); foreach (MetaData md in lfr.entries) { FileEntry ife = new FileEntry(md.name); if (md.IsFile) { ife.IsFolder = false; ife.Size = (long)md.size; } else { ife.IsFolder = true; } list.Add(ife); } if (lfr.has_more) { do { lfr = dbx.ListFilesContinue(lfr.cursor); foreach (MetaData md in lfr.entries) { FileEntry ife = new FileEntry(md.name); if (md.IsFile) { ife.IsFolder = false; ife.Size = (long) md.size; } else { ife.IsFolder = true; } list.Add(ife); } } while (lfr.has_more); } return list; } catch (DropboxException de) { if (de.errorJSON["error"][".tag"].ToString() == "path") { if (de.errorJSON["error"]["path"][".tag"].ToString() == "not_found") { throw new FolderMissingException(); } else { throw; } } else { throw; } } }
public static FileEntry ParseLine(string line) { Match m = MatchLine(line); if (m == null) return null; FileEntry f = new FileEntry(m.Groups["name"].Value); string time = m.Groups["timestamp"].Value; string dir = m.Groups["dir"].Value; //Unused //string permission = m.Groups["permission"].Value; if (dir != "" && dir != "-") f.IsFolder = true; else f.Size = long.Parse(m.Groups["size"].Value); DateTime t; if (DateTime.TryParse(time, out t)) f.LastAccess = f.LastModification = t; return f; }
public List<IFileEntry> List() { List<IFileEntry> ls = new List<IFileEntry>(); PreAuthenticate(); if (!System.IO.Directory.Exists(m_path)) throw new FolderMissingException(string.Format(Strings.FileBackend.FolderMissingError, m_path)); foreach (string s in System.IO.Directory.GetFiles(m_path)) { System.IO.FileInfo fi = new System.IO.FileInfo(s); ls.Add(new FileEntry(fi.Name, fi.Length, fi.LastAccessTime, fi.LastWriteTime)); } foreach (string s in System.IO.Directory.GetDirectories(m_path)) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(s); FileEntry fe = new FileEntry(di.Name, 0, di.LastAccessTime, di.LastWriteTime); fe.IsFolder = true; ls.Add(fe); } return ls; }
public List<IFileEntry> List() { int offset = 0; int count = FILE_LIST_PAGE_SIZE; var files = new List<IFileEntry>(); m_fileidCache.Clear(); while(count == FILE_LIST_PAGE_SIZE) { var url = string.Format("{0}/{1}?access_token={2}&limit={3}&offset={4}", WLID_SERVER, string.Format(FOLDER_TEMPLATE, FolderID), Library.Utility.Uri.UrlEncode(m_oauth.AccessToken), FILE_LIST_PAGE_SIZE, offset); var res = m_oauth.GetJSONData<WLID_DataItem>(url); if (res != null && res.data != null) { count = res.data.Length; foreach(var r in res.data) { m_fileidCache.Add(r.name, r.id); var fe = new FileEntry(r.name, r.size, r.updated_time, r.updated_time); fe.IsFolder = string.Equals(r.type, "folder", StringComparison.InvariantCultureIgnoreCase); files.Add(fe); } } else { count = 0; } offset += count; } return files; }
public List<IFileEntry> List() { System.Net.HttpWebRequest req = CreateRequest(""); req.Method = "PROPFIND"; req.Headers.Add("Depth", "1"); req.ContentType = "text/xml"; req.ContentLength = PROPFIND_BODY.Length; using (System.IO.Stream s = req.GetRequestStream()) s.Write(PROPFIND_BODY, 0, PROPFIND_BODY.Length); try { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); using (System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)req.GetResponse()) { int code = (int)resp.StatusCode; if (code < 200 || code >= 300) //For some reason Mono does not throw this automatically throw new System.Net.WebException(resp.StatusDescription, null, System.Net.WebExceptionStatus.ProtocolError, resp); if (!string.IsNullOrEmpty(m_debugPropfindFile)) { using (System.IO.FileStream fs = new System.IO.FileStream(m_debugPropfindFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)) Utility.Utility.CopyStream(resp.GetResponseStream(), fs, false); doc.Load(m_debugPropfindFile); } else doc.Load(resp.GetResponseStream()); } System.Xml.XmlNamespaceManager nm = new System.Xml.XmlNamespaceManager(doc.NameTable); nm.AddNamespace("D", "DAV:"); List<IFileEntry> files = new List<IFileEntry>(); m_filenamelist = new List<string>(); foreach (System.Xml.XmlNode n in doc.SelectNodes("D:multistatus/D:response/D:href", nm)) { //IIS uses %20 for spaces and %2B for + //Apache uses %20 for spaces and + for + string name = System.Web.HttpUtility.UrlDecode(n.InnerText.Replace("+", "%2B")); string cmp_path; //TODO: This list is getting ridiculous, should change to regexps if (name.StartsWith(m_url)) cmp_path = m_url; else if (name.StartsWith(m_rawurl)) cmp_path = m_rawurl; else if (name.StartsWith(m_rawurlPort)) cmp_path = m_rawurlPort; else if (name.StartsWith(m_path)) cmp_path = m_path; else if (name.StartsWith(m_sanitizedUrl)) cmp_path = m_sanitizedUrl; else if (name.StartsWith(m_reverseProtocolUrl)) cmp_path = m_reverseProtocolUrl; else continue; if (name.Length <= cmp_path.Length) continue; name = name.Substring(cmp_path.Length); long size = -1; DateTime lastAccess = new DateTime(); DateTime lastModified = new DateTime(); bool isCollection = false; System.Xml.XmlNode stat = n.ParentNode.SelectSingleNode("D:propstat/D:prop", nm); if (stat != null) { System.Xml.XmlNode s = stat.SelectSingleNode("D:getcontentlength", nm); if (s != null) size = long.Parse(s.InnerText); s = stat.SelectSingleNode("D:getlastmodified", nm); if (s != null) try { //Not important if this succeeds lastAccess = lastModified = DateTime.Parse(s.InnerText, System.Globalization.CultureInfo.InvariantCulture); } catch { } s = stat.SelectSingleNode("D:iscollection", nm); if (s != null) isCollection = s.InnerText.Trim() == "1"; else isCollection = (stat.SelectSingleNode("D:resourcetype/D:collection", nm) != null); } FileEntry fe = new FileEntry(name, size, lastAccess, lastModified); fe.IsFolder = isCollection; files.Add(fe); m_filenamelist.Add(name); } return files; } catch (System.Net.WebException wex) { if (wex.Response as System.Net.HttpWebResponse != null && ((wex.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.NotFound || (wex.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.Conflict)) throw new Interface.FolderMissingException(string.Format(Strings.WEBDAV.MissingFolderError, m_path, wex.Message), wex); throw; } }
public List<IFileEntry> List() { try { var res = new List<IFileEntry>(); m_filecache.Clear(); foreach(var n in ListFolder(CurrentFolderId)) { FileEntry fe = null; if (n.fileSize == null) fe = new FileEntry(n.title); else if (n.modifiedDate == null) fe = new FileEntry(n.title, n.fileSize.Value); else fe = new FileEntry(n.title, n.fileSize.Value, n.modifiedDate.Value, n.modifiedDate.Value); if (fe != null) { fe.IsFolder = FOLDER_MIMETYPE.Equals(n.mimeType, StringComparison.InvariantCultureIgnoreCase); res.Add(fe); if (!fe.IsFolder) { GoogleDriveFolderItem[] lst; if (!m_filecache.TryGetValue(fe.Name, out lst)) m_filecache[fe.Name] = new GoogleDriveFolderItem[] { n }; else { Array.Resize(ref lst, lst.Length + 1); lst[lst.Length - 1] = n; } } } } return res; } catch { m_filecache.Clear(); throw; } }
private List<IFileEntry> doList(bool useNewContext) { SP.ClientContext ctx = getSpClientContext(useNewContext); try { SP.Folder remoteFolder = ctx.Web.GetFolderByServerRelativeUrl(m_serverRelPath); ctx.Load(remoteFolder, f => f.Exists); ctx.Load(remoteFolder, f => f.Files, f => f.Folders); wrappedExecuteQueryOnConext(ctx, m_serverRelPath, true); if (!remoteFolder.Exists) throw new Interface.FolderMissingException(Strings.SharePoint.MissingElementError(m_serverRelPath, m_spWebUrl)); List<IFileEntry> files = new List<IFileEntry>(remoteFolder.Folders.Count + remoteFolder.Files.Count); foreach (var f in remoteFolder.Folders.Where(ff => ff.Exists)) { FileEntry fe = new FileEntry(f.Name, -1, f.TimeLastModified, f.TimeLastModified); // f.TimeCreated fe.IsFolder = true; files.Add(fe); } foreach (var f in remoteFolder.Files.Where(ff => ff.Exists)) { FileEntry fe = new FileEntry(f.Name, f.Length, f.TimeLastModified, f.TimeLastModified); // f.TimeCreated fe.IsFolder = false; files.Add(fe); } return files; } catch (ServerException) { throw; /* rethrow if Server answered */ } catch (Interface.FileMissingException) { throw; } catch (Interface.FolderMissingException) { throw; } catch { if (!useNewContext) /* retry */ return doList(true); else throw; } finally { } }
public List<IFileEntry> List() { TahoeEl data; try { var req = CreateRequest("", "t=json"); req.Method = System.Net.WebRequestMethods.Http.Get; var areq = new Utility.AsyncHttpRequest(req); using (System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)areq.GetResponse()) { int code = (int)resp.StatusCode; if (code < 200 || code >= 300) //For some reason Mono does not throw this automatically throw new System.Net.WebException(resp.StatusDescription, null, System.Net.WebExceptionStatus.ProtocolError, resp); using (var rs = areq.GetResponseStream()) using (var sr = new System.IO.StreamReader(rs)) using (var jr = new Newtonsoft.Json.JsonTextReader(sr)) { var jsr =new Newtonsoft.Json.JsonSerializer(); jsr.Converters.Add(new TahoeElConverter()); data = jsr.Deserialize<TahoeEl>(jr); } } } catch (System.Net.WebException wex) { //Convert to better exception if (wex.Response as System.Net.HttpWebResponse != null) if ((wex.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.Conflict || (wex.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.NotFound) throw new Interface.FolderMissingException(Strings.TahoeBackend.MissingFolderError(m_url, wex.Message), wex); throw; } if (data == null || data.node == null || data.nodetype != "dirnode") throw new Exception("Invalid folder listing response"); var files = new List<IFileEntry>(); foreach (var e in data.node.children) { if (e.Value == null || e.Value.node == null) continue; bool isDir = e.Value.nodetype == "dirnode"; bool isFile = e.Value.nodetype == "filenode"; if (!isDir && !isFile) continue; FileEntry fe = new FileEntry(e.Key); fe.IsFolder = isDir; if (e.Value.node.metadata != null && e.Value.node.metadata.tahoe != null) fe.LastModification = Duplicati.Library.Utility.Utility.EPOCH + TimeSpan.FromSeconds(e.Value.node.metadata.tahoe.linkmotime); if (isFile) fe.Size = e.Value.node.size; files.Add(fe); } return files; }
public List<IFileEntry> List() { LitJson.JsonData data; try { System.Net.HttpWebRequest req = CreateRequest("", "t=json"); req.Method = System.Net.WebRequestMethods.Http.Get; using (System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)req.GetResponse()) { int code = (int)resp.StatusCode; if (code < 200 || code >= 300) //For some reason Mono does not throw this automatically throw new System.Net.WebException(resp.StatusDescription, null, System.Net.WebExceptionStatus.ProtocolError, resp); //HACK: We need the LitJSON to use Invariant culture, otherwise it cannot parse doubles System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture; try { System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; using (System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream())) data = LitJson.JsonMapper.ToObject(sr); } finally { try { System.Threading.Thread.CurrentThread.CurrentCulture = ci; } catch { } } } } catch (System.Net.WebException wex) { //Convert to better exception if (wex.Response as System.Net.HttpWebResponse != null) if ((wex.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.Conflict || (wex.Response as System.Net.HttpWebResponse).StatusCode == System.Net.HttpStatusCode.NotFound) throw new Interface.FolderMissingException(string.Format(Strings.TahoeBackend.MissingFolderError, m_url, wex.Message), wex); throw; } if (data.Count < 2 || !data[0].IsString || (string)data[0] != "dirnode") throw new Exception(string.Format(Strings.TahoeBackend.UnexpectedJsonFragmentType, data.Count < 1 ? "<null>" : data[0], "dirnode")); if (!data[1].IsObject) throw new Exception(string.Format(Strings.TahoeBackend.UnexpectedJsonFragmentType, data[1], "Json object")); if (!(data[1] as System.Collections.IDictionary).Contains("children") || !data[1]["children"].IsObject || !(data[1]["children"] is System.Collections.IDictionary)) throw new Exception(string.Format(Strings.TahoeBackend.UnexpectedJsonFragmentType, data[1], "children")); List<IFileEntry> files = new List<IFileEntry>(); foreach (string key in ((System.Collections.IDictionary)data[1]["children"]).Keys) { LitJson.JsonData entry = data[1]["children"][key]; if (!entry.IsArray || entry.Count < 2 || !entry[0].IsString || !entry[1].IsObject) continue; bool isDir = ((string)entry[0]) == "dirnode"; bool isFile = ((string)entry[0]) == "filenode"; if (!isDir && !isFile) continue; FileEntry fe = new FileEntry(key); fe.IsFolder = isDir; if (((System.Collections.IDictionary)entry[1]).Contains("metadata")) { LitJson.JsonData fentry = entry[1]["metadata"]; if (fentry.IsObject && ((System.Collections.IDictionary)fentry).Contains("tahoe")) { fentry = fentry["tahoe"]; if (fentry.IsObject && ((System.Collections.IDictionary)fentry).Contains("linkmotime")) { try { fe.LastModification = ((DateTime)(Library.Utility.Utility.EPOCH + TimeSpan.FromSeconds((double)fentry["linkmotime"])).ToLocalTime()); } catch { } } } } if (((System.Collections.IDictionary)entry[1]).Contains("size")) { try { if (entry[1]["size"].IsInt) fe.Size = (int)entry[1]["size"]; else if (entry[1]["size"].IsLong) fe.Size = (long)entry[1]["size"]; } catch {} } files.Add(fe); } return files; }