public void UploadFile(String localFileName, String remoteFileName, Int32 remoteFilePermissions = 0x0666) { var adbFileInfo = GetFileInfo(remoteFileName); if (adbFileInfo.IsDirectory || adbFileInfo.IsSymbolicLink) { remoteFileName = AdbHelpers.CombinePath(remoteFileName, Path.GetFileName(localFileName)); } using (var adbSocket = GetSocket()) { var response = SendSyncCommand(adbSocket, "SEND", $"{remoteFileName},{remoteFilePermissions}", false); var localFileInfo = new FileInfo(localFileName); var left = (Int32)localFileInfo.Length; using (var stream = File.OpenRead(localFileName)) { var bytes = new Byte[65536]; while (left > 0) { var size = left < bytes.Length ? left : bytes.Length; stream.Read(bytes, 0, size); adbSocket.WriteString("DATA"); adbSocket.WriteInt32(size); adbSocket.Write(bytes, size); left -= size; } } adbSocket.WriteString("DONE"); adbSocket.WriteInt32(AdbHelpers.ToUnixTime(localFileInfo.LastWriteTime)); response = adbSocket.ReadString(4); if (!response.Equals("OKAY")) { throw new AdbInvalidResponseException(response); } } }
private AdbFileInfo GetFileInfo(AdbSocket adbSocket, String fullName, String directoryName) { var mode = adbSocket.ReadInt32(); var size = adbSocket.ReadInt32(); var time = AdbHelpers.FromUnixTime(adbSocket.ReadInt32()); var name = ""; if (String.IsNullOrEmpty(fullName)) { name = adbSocket.ReadSyncString(); if (name.Equals(".") || name.Equals("..")) { return(null); } fullName = AdbHelpers.CombinePath(directoryName, name); } else { name = Path.GetFileName(fullName); } return(new AdbFileInfo(fullName, name, size, mode, time)); }