protected override string OnProcess(string sMessage) { string sFile = GetPath(sMessage); if (ConnectionObject.FileSystemObject.FileExists(sFile)) { return(GetMessage(553, "File already exists.")); } FileSystem.IFile file = ConnectionObject.FileSystemObject.OpenFile(sFile, true); FtpReplySocket socketReply = new FtpReplySocket(ConnectionObject); if (!socketReply.Loaded) { return(GetMessage(425, "Error in establishing data connection.")); } byte [] abData = new byte[m_nBufferSize]; Assemblies.General.SocketHelpers.Send(ConnectionObject.Socket, GetMessage(150, "Opening connection for data transfer.")); int nReceived = socketReply.Receive(abData); while (nReceived > 0) { file.Write(abData, nReceived); nReceived = socketReply.Receive(abData); } file.Close(); socketReply.Close(); return(GetMessage(226, "Uploaded file successfully.")); }
protected override async Task <string> OnProcess(string sMessage) { string sFile = GetPath(sMessage); FileSystem.IFile file = ConnectionObject.FileSystemObject.OpenFile(sFile, true); if (file == null) { return(await GetMessage(425, "Couldn't open file")); } FtpReplySocket socketReply = new FtpReplySocket(ConnectionObject); if (!socketReply.Loaded) { return(await GetMessage(425, "Error in establishing data connection.")); } byte [] abData = new byte[m_nBufferSize]; await Assemblies.General.SocketHelpers.Send(ConnectionObject.Socket, await GetMessage(150, "Opening connection for data transfer.")); int nReceived = socketReply.Receive(abData); while (nReceived > 0) { nReceived = socketReply.Receive(abData); file.Write(abData, nReceived); } file.Close(); socketReply.Close(); return(await GetMessage(226, string.Format("Appended file successfully. ({0})", sFile))); }
protected override async Task <string> OnProcess(string sMessage) { string sFilePath = GetPath(sMessage); if (!ConnectionObject.FileSystemObject.FileExists(sFilePath)) { return(await GetMessage(550, "File doesn't exist")); } FtpReplySocket replySocket = new FtpReplySocket(ConnectionObject); if (!replySocket.Loaded) { return(await GetMessage(550, "Unable to establish data connection")); } await Assemblies.General.SocketHelpers.Send(ConnectionObject.Socket, "150 Starting data transfer, please wait...\r\n"); const int m_nBufferSize = 65536; FileSystem.IFile file = ConnectionObject.FileSystemObject.OpenFile(sFilePath, false); if (file == null) { return(await GetMessage(550, "Couldn't open file")); } byte [] abBuffer = new byte[m_nBufferSize]; int nRead = file.Read(abBuffer, m_nBufferSize); while (nRead > 0 && await replySocket.Send(abBuffer, nRead)) { nRead = file.Read(abBuffer, m_nBufferSize); } file.Close(); replySocket.Close(); return(await GetMessage(226, "File download succeeded.")); }