public override void Execute() { IFtpMessage serverResponce = ExecutorState.ServerConnection.SendWithResponce(FtpMessage); IFtpMessage commandResult = null; if (FtpMessage.Args.StartsWith("P")) { ExecutorState.ClientConnection.SetDataEncryptionStatus(true); if (serverResponce.CommandType == ServerCommandType.Success) { ExecutorState.ServerConnection.SetDataEncryptionStatus(true); } commandResult = new FtpMessage(ServerMessageCode.Success, "Data protection enabled", ExecutorState.ClientConnection.Encoding); } if (FtpMessage.Args.StartsWith("C")) { ExecutorState.ClientConnection.SetDataEncryptionStatus(false); ExecutorState.ServerConnection.SetDataEncryptionStatus(false); commandResult = new FtpMessage(ServerMessageCode.Success, "Data protection not enabled", ExecutorState.ClientConnection.Encoding); } commandResult = commandResult ?? new FtpMessage(ServerMessageCode.UnknownCommand, "Unknown command", ExecutorState.ClientConnection.Encoding); ExecutorState.ClientConnection.SendMessage(commandResult); }
public override void Execute() { IFtpMessage ftpMessage = new FtpMessage(ServerMessageCode.Unauthorized, "Please login with USER and PASS.", ExecutorState.ClientConnection.Encoding); ExecutorState.ClientConnection.SendMessage(ftpMessage); }
void SendRequest() { var msg = new FtpMessage { Id = random.Next(1000), Name = "John Smith" }; Bus.Send(msg); Console.WriteLine("Request sent id: " + msg.Id); }
public static void SendFileToFtps([Ftp] out FtpMessage ftpMessage) { var stream = new MemoryStream(Encoding.UTF8.GetBytes("Nu skickar vi en fil!")); ftpMessage = new FtpMessage { Filename = "/tmp/testfile.txt", Data = stream }; }
public override void Execute() { IConnection clientConnection = ExecutorState.ClientConnection; FtpMessage responce = new FtpMessage("331 Password required", clientConnection.Encoding); clientConnection.UserChanged = true; clientConnection.UserLogin = _commandArgsResolver.ResolveUserLogin(FtpMessage.Args); clientConnection.RemoteServerIdentifier = _commandArgsResolver.ResolveServerIdentifier(FtpMessage.Args); SendToClient(responce); }
public IFtpMessage GetMessage() { if (_messageQueue.Count > 0) { return(_messageQueue.Dequeue()); } if (!IsConnected) { return(null); } byte[] buffer = new byte[CommandBufferSize]; try { using (MemoryStream ms = new MemoryStream()) { lock (_activeStreamLocker) { int count; while ((count = AciveStream.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, count); if ((char)buffer[count - 1] == '\n' && (char)buffer[count - 2] == '\r') { if (ConnectionType == ConnectionType.Client || FtpMessage.IsFullServerCommand(ms.ToArray(), Encoding)) { foreach (FtpMessage ftpMessage in FtpMessage.GetMessages(ms.ToArray(), Encoding, ConnectionType)) { _messageQueue.Enqueue(ftpMessage); } break; } } } } if (_messageQueue.Count > 0) { return(_messageQueue.Dequeue()); } } } catch (Exception ex) { Logger.Log.Error(ex.Message, ex); } return(null); }
public override void ExecuteJob(IJobExecutionMessage message, IMQTransaction transaction) { //DirectoryInfo directory = new DirectoryInfo(dir); //string[] files = (string[])directory.GetFiles("topup_*").Where(f => DateTime.Compare(DateTime.Now.AddHours(-1.0), f.CreationTime) < 0) // .Select(z => z.Name).ToArray(); string topups = GetTopupFileNames(); if (!topups.Equals("")) { FtpMessage ftpMessage = new FtpMessage(); ftpMessage.FileName = "ProcessedPaymentFiles_" + DateTime.Now.ToString("yyyyMMddhh24mmss") + ".txt"; ftpMessage.Body = Encoding.ASCII.GetBytes(topups); ftpClient.SendMessage(ftpMessage); } }
private async Task SendBySftp(FtpMessage ftpMessage) { var host = ftpMessage.Configuration.FtpHost; var path = ftpMessage.Filename; var username = ftpMessage.Configuration.Username; var password = ftpMessage.Configuration.Password; var port = ftpMessage.Configuration.FtpPort; using (var sftpClient = new SftpClient(host.Host, port, username, password)) { sftpClient.Connect(); //sftpClient.ChangeDirectory("tmp"); var ms = new MemoryStream(ftpMessage.Data); sftpClient.UploadFile(ms, path); sftpClient.Disconnect(); } }
public void Run() { while (true) { Console.WriteLine("\n\nEnter ID: "); String id = Console.ReadLine(); Console.WriteLine("Enter Name: "); String name = Console.ReadLine(); var msg = new FtpMessage(); msg.ID = Int32.Parse(id); msg.Name = name; this.Bus.Send(msg).Register <FtpReply>(t => Console.WriteLine("Reply Received: " + t.OtherData.ToString())); Console.ReadLine(); } }
public async Task SendFileAsync(FtpMessage ftpMessage) { if (ftpMessage.Send) { switch (ftpMessage.Configuration.FtpHost.Scheme) { case "sftp": await SendBySftp(ftpMessage); break; case "ftps": await SendByFtps(ftpMessage); break; default: throw new ArgumentException("Unsupported uri scheme. Only ftps and sftp is supported.", nameof(ftpMessage)); } } }
public override void Execute() { IFtpMessage ftpMessage; IConnection clientConnection = ExecutorState.ClientConnection; bool needProtectConnection = true; if (!FtpMessage.Args.StartsWith("TLS")) { ftpMessage = new FtpMessage("504 поддерживается только TLS протокол", clientConnection.Encoding); needProtectConnection = false; } else { ftpMessage = new FtpMessage("234 открытие TLS соединения", clientConnection.Encoding); } clientConnection.SendMessage(ftpMessage); if (needProtectConnection) { clientConnection.SetUpSecureConnectionAsServer(GetClientCertificate()); } }
private async Task SendByFtps(FtpMessage ftpMessage) { var host = ftpMessage.Configuration.FtpHost; var path = ftpMessage.Filename; var username = ftpMessage.Configuration.Username; var password = ftpMessage.Configuration.Password; var port = ftpMessage.Configuration.FtpPort; using (var client = new FTPSClient()) { client.Connect(host.Host, new NetworkCredential(username, password), ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested); var ftps = client.PutFile(path); await ftps.WriteAsync(ftpMessage.Data, 0, ftpMessage.Data.Length); ftps.Close(); } }
public void SendCommand(string stringCommand) { FtpMessage command = new FtpMessage(stringCommand, Encoding); SendMessage(command); }
public static void StartONServiceBus([ServiceBusTrigger("")] BrokeredMessage messagein, [Ftp("filnamn.txt", cog)] FtpMessage ftpMessage, [Ftp(config2)] FtpMessage ftpMessage2) => ftpMessage = ftpMessage2;
public override void Execute() { _dataConnection = _connectionFactory.CreateDataConnection(DataConnectionType.Active); _dataConnection.Connection = _commandExecutorHelper.GetActiveDataConnection(FtpMessage); _dataConnectionListener = new TcpListener(ServerConnection.LocalEndPoint.Address, 0); _dataConnectionListener.Start(); IPEndPoint passiveListenerEndpoint = (IPEndPoint)_dataConnectionListener.LocalEndpoint; byte[] address = passiveListenerEndpoint.Address.GetAddressBytes(); short clientPort = (short)passiveListenerEndpoint.Port; byte[] clientPortArray = BitConverter.GetBytes(clientPort); if (BitConverter.IsLittleEndian) { Array.Reverse(clientPortArray); } int ipver; switch (passiveListenerEndpoint.AddressFamily) { case AddressFamily.InterNetwork: ipver = 1; break; case AddressFamily.InterNetworkV6: ipver = 2; break; default: throw new InvalidOperationException("The IP protocol being used is not supported."); } // созданы команды для двух типов подключения чтобы в случае когда сервер не поддерживает одну из них - использовать вторую FtpMessage portCommand = new FtpMessage( String.Format("PORT {0},{1},{2},{3},{4},{5}", address[0], address[1], address[2], address[3], clientPortArray[0], clientPortArray[1]), ServerConnection.Encoding); FtpMessage eprtCommand = new FtpMessage( String.Format("EPRT |{0}|{1}|{2}|", ipver, passiveListenerEndpoint.Address, passiveListenerEndpoint.Port), ServerConnection.Encoding); FtpMessage successfulResponce = new FtpMessage( String.Format("200 {0} command successful", FtpMessage.CommandName), ClientConnection.Encoding); List <IFtpMessage> messagesQueue = new List <IFtpMessage>(); if (FtpMessage.CommandName == ProcessingClientCommand.Port) { messagesQueue.Add(portCommand); messagesQueue.Add(eprtCommand); } else { messagesQueue.Add(eprtCommand); messagesQueue.Add(portCommand); } foreach (IFtpMessage message in messagesQueue) { IFtpMessage serverResponse = SendWithResponceServer(message); if (serverResponse.CommandType != ServerCommandType.Error) { SendToClient(successfulResponce); return; } } _dataConnectionListener.Stop(); _dataConnectionListener = null; SendToClient(new FtpMessage("451 can't open data connection", ClientConnection.Encoding)); }
public override void Execute() { FtpMessage responce = new FtpMessage("230 успешная авторизация", ClientConnection.Encoding); ClientConnection.Password = _commandArgsResolver.ResolvePassword(FtpMessage.Args); if (String.IsNullOrEmpty(ClientConnection.UserLogin) || String.IsNullOrEmpty(ClientConnection.Password) || String.IsNullOrEmpty(ClientConnection.RemoteServerIdentifier)) { //TODO ctor SendToClient(new FtpMessage("530 неверная последовательность команд", ClientConnection.Encoding)); return; } IUserCheckerResult checkerResult = _userChecker.Check(ClientConnection.UserLogin, ClientConnection.Password, ClientConnection.RemoteServerIdentifier); if (checkerResult == null) { SendToClient(new FtpMessage("530 Неверная комбинация логин-пароль", ClientConnection.Encoding)); return; } try { _serverConnectionBuilder.BuildRemoteConnection(checkerResult.UrlAddress, checkerResult.Port); } catch (AuthenticationException) { Logger.Log.Error(String.Format("remote server anavailable: {0}| USER: {1}", checkerResult.UrlAddress, ClientConnection.UserLogin)); SendToClient(new FtpMessage("434 remote server anavailable", ClientConnection.Encoding)); return; } try { _serverConnectionBuilder.BuildConnectionSecurity(); } catch (AuthenticationException e) { Logger.Log.Error(String.Format("BuildConnectionSecurity: {0}, Host: {1}, User: {2}", e.Message, checkerResult.UrlAddress, ClientConnection.UserLogin)); } try { _serverConnectionBuilder.BuildUser(checkerResult.Login); _serverConnectionBuilder.BuildPass(checkerResult.Pass); } catch (AuthenticationException e) { Logger.Log.Error(String.Format("BuildUserPass: {0}; Host: {1}, User: {2}", e.Message, checkerResult.UrlAddress, ClientConnection.UserLogin)); SendToClient(new FtpMessage("425 incorrect remote server auth data. Please contact the administrator", ClientConnection.Encoding)); return; } SendToClient(responce); }