Exemplo n.º 1
0
        public async Task <bool> WriteImageSourceAsByteArraySFTP(ImageSource imageSource, string imageLocationMemory)
        {
            var taskResult = await Task.Run(() =>
            {
                BitmapEncoder encoder = new TiffBitmapEncoder();
                byte[] biteArray      = ImageSourceToBytes(encoder, imageSource); // Function returns byte[] csv file

                using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password))
                {
                    client.Connect();
                    if (client.IsConnected)
                    {
                        client.ChangeDirectory(SFTPWorkingDirectory);
                        using (var ms = new MemoryStream(biteArray))
                        {
                            client.BufferSize = (uint)ms.Length;                                               // bypass Payload error large files
                            client.Create(SFTPWorkingDirectory + "/" + imageLocationMemory);
                            client.WriteAllBytes(SFTPWorkingDirectory + "/" + imageLocationMemory, biteArray); // imageLocationDisk == openFileDialog.FileName
                            return(true);
                        }
                    }
                    else
                    {
                        OutputMessage = "Couldn't connect to SFTP server.";
                        return(false);
                    }
                }
            });

            return(taskResult);
        }