/// <summary> /// Executes the request message on the target system and returns a response message. /// If there isn’t a response, this method should return null /// </summary> public Message Execute(Message message, TimeSpan timeout) { var generator = new NameGenerator(message, Connection.ConnectionFactory.ConnectionUri.Path, Connection.ConnectionFactory.ConnectionUri.FileName); string sourcePath = new Uri(message.Headers.Action).LocalPath; string targetFolder = generator.Folder; string targetPath = Path.Combine(targetFolder, generator.FileName).Replace('\\', '/'); if (!targetPath.StartsWith("/")) targetPath = string.Concat("/", targetPath); var client = Connection.Client; if (!client.DirectoryExists(targetFolder)) client.CreateDirectory(targetFolder); Stream outputStream = null; switch (Connection.ConnectionFactory.Adapter.OverwriteAction) { case OverwriteAction.None: if (client.FileExists(targetPath)) throw new FtpException(string.Format("The file '{0}' already exists.", targetPath)); outputStream = client.OpenWrite(targetPath); break; case OverwriteAction.Replace: outputStream = client.OpenWrite(targetPath); break; case OverwriteAction.Append: outputStream = client.OpenAppend(targetPath); break; } using (outputStream) { var inputStream = message.GetBody<Stream>(); inputStream.CopyTo(outputStream); return Message.CreateMessage(MessageVersion.Default, string.Empty); } }
/// <summary> /// Executes the request message on the target system and returns a response message. /// If there isn’t a response, this method should return null /// </summary> public Message Execute(Message message, TimeSpan timeout) { var generator = new NameGenerator(message, Connection.ConnectionFactory.ConnectionUri.Path, Connection.ConnectionFactory.ConnectionUri.FileName); string sourcePath = new Uri(message.Headers.Action).LocalPath; string targetFolder = generator.Folder; string targetPath = Path.Combine(targetFolder, generator.FileName); if (!Directory.Exists(targetFolder)) Directory.CreateDirectory(targetFolder); Stream outputStream = null; switch (Connection.ConnectionFactory.Adapter.OverwriteAction) { case OverwriteAction.None: outputStream = System.IO.File.Open(targetPath, FileMode.CreateNew); break; case OverwriteAction.Replace: outputStream = System.IO.File.Create(targetPath); break; case OverwriteAction.Append: outputStream = System.IO.File.OpenWrite(targetPath); break; } using (outputStream) { var inputStream = message.GetBody<Stream>(); inputStream.CopyTo(outputStream); return Message.CreateMessage(MessageVersion.Default, string.Empty); } }