public void OnFileSendResponse(int file, int uploadToken) { _isDone = false; //Client.ResetTimeout(); if (Stream == null) { try { Stream = new FileStream(FileName, FileMode.Open); } catch (IOException err) { _connection.Send(FileClientHelper.SendFileFailed(FileName, err.Message)); if (_request.IsType(SendFileRequest.CommandType.SENDFILE)) { _connection.Send(FileClientHelper.SendDirectoryFailed()); } return; } } { int size = Stream.Read(_buffer.Buffer, ByteArray.HEADERLENGTH, 1024 * 16 - ByteArray.HEADERLENGTH); _sentSize = size; _buffer.Reset(); _buffer.AdjustWriter(ByteArray.HEADERLENGTH + size); _buffer.RefreshHeader(); _connection.Send(FileClientHelper.RequestFileBlock(FileName, 0, size, _buffer, 0)); if (Callback != null) { Callback.OnSendStarted((int)Stream.Length, size); } } }
public void SendDirectory(string dir, string remotedir) { if (!_request.InitDirectoryCommandQueue(dir, remotedir, BaseDir, CurrentDir)) { _connection.Send(FileClientHelper.SendDirectoryFailed()); return; } _connection.Send(FileClientHelper.StartBatch(remotedir)); _request.ExecuteNext(this); }
public void OnFileBlockResponse(int file, int blockId) { if (Stream == null) { try { Stream = new FileStream(FileName, FileMode.Open); } catch (IOException err) { _connection.Send(FileClientHelper.SendFileFailed(FileName, err.Message)); if (_request.IsType(SendFileRequest.CommandType.SENDFILE)) { _connection.Send(FileClientHelper.SendDirectoryFailed()); } return; } } //Client.ResetTimeout(); Stream.Seek(_sentSize, SeekOrigin.Begin); int size = Stream.Read(_buffer.Buffer, ByteArray.HEADERLENGTH, 1024 * 16 - ByteArray.HEADERLENGTH); _sentSize += size; if (size != 0) { _buffer.Reset(); _buffer.AdjustWriter(ByteArray.HEADERLENGTH + size); _buffer.RefreshHeader(); _connection.Send(FileClientHelper.RequestFileBlock(FileName, ++blockId, size, _buffer, _sentSize >= Stream.Length ? -1 : 0)); if (Callback != null) { Callback.OnSendProgress(size, (int)Stream.Length, _sentSize); } } else { if (Callback != null && !_isDone) { Callback.OnSendFailed(FileTransferError.None); _isDone = true; } //Client.FinishSending(); Stream.Dispose(); Stream = null; if (_request.CompleteCommand(SendFileRequest.CommandType.SENDFILE)) { _request.ExecuteNext(this); } } }
public void SendFile(string file, string remoteFile) { FileInfo f = new FileInfo(file); if (f.Exists) { FileName = f.FullName; //Callback = _callback; _connection.Send(FileClientHelper.RequestFileSend(remoteFile, UploadTag, (int)f.Length)); } }
public bool HandleProtocol(com.ideadynamo.foundation.buffer.ByteArray buffer) { if (_fileReceiveSession != null) { if (FileServerHelper.IntepretMessage(buffer, _fileReceiveSession)) { return(true); } } if (_fileSendSession != null) { if (FileClientHelper.IntepretMessage(buffer, _fileSendSession)) { return(true); } } return(false); }
public void CreateDirectory(string dir) { _connection.Send(FileClientHelper.CreateDirectory(dir)); }
public void SetWorkingDir(string dir) { _connection.Send(FileClientHelper.SetWorkingDirectory(dir)); }