Ejemplo n.º 1
0
        public Task<bool> UploadFile (string destination, string file)
		{
			return Task.Run (() => {
				try {
					var remoteExplorer = new RemoteExplorer ();

					if (destination.Count (e => e == '/') > 1) {
						int index = destination.IndexOf ('/', destination.IndexOf ('/') + 1);
						var rootFolder = destination.Substring (0, index);
						var folder = GetFolder (rootFolder).Result;

						if (folder.HasCryptoKeys) {
							Rijndael rijndael = Rijndael.Create (); 
							rijndael.Key = folder.Key; 
							rijndael.IV = folder.IV; 

							using (var stream = new CryptoStream (File.OpenRead (file), rijndael.CreateEncryptor (), CryptoStreamMode.Read)) {
								return remoteExplorer.UploadFile (destination, stream);
							}
						}
					}

					using (var stream = File.OpenRead (file)) {
						return remoteExplorer.UploadFile (destination, stream);
					}
				} catch (Exception ex){
					Insights.Report(ex);
					return false;
				}

			});
		}