public void TestGetFile() { //GET /files/:path_and_filename Session session = BrickFtp.Login(domain, username, password); var filePath = "/Testtt/Forecast_MG_GwyntYMor_21_0_2016060200.csv"; FtpFileContent fileWithContent = BrickFtp.GetFile(session, filePath); Assert.IsTrue(fileWithContent.Content.Length > 0); }
//GET /files/:path_and_filename public static FtpFileContent GetFile(Session session, string pathToFile) { if (session == null) { throw new ArgumentException("Session cannot be null, please login to get a valid session object."); } pathToFile = pathToFile.TrimStart('/'); string basePath = Protocol + session.Domain; var operationPath = "/api/rest/v1/files/" + session.Username + "/" + pathToFile; operationPath = operationPath.TrimEnd('/'); var headerParams = new Dictionary <String, String>(); var queryParams = new Dictionary <String, object>(); var postParams = new Dictionary <String, object>(); try { string response = Invoke(basePath, operationPath, "GET", queryParams, postParams, headerParams, sessionCookie: session.Cookie); if (response != null) { var ftpItem = (FtpDownloadItem)BrickFtp.Deserialize(response, typeof(FtpDownloadItem)); using (var client = new HttpClient()) { // HTTP GET Task <byte[]> r = client.GetByteArrayAsync(ftpItem.download_uri); r.Wait(); if (r.Status == TaskStatus.RanToCompletion) { byte[] array = r.Result; //var str = System.Text.Encoding.Default.GetString(array); var fileContent = new FtpFileContent(ftpItem, array); return(fileContent); } } } } catch (BrickFtpException ex) { if (ex.ErrorCode == 404) { return(null); } throw; } return(null); }