Esempio n. 1
0
        public async Task <byte[]> ReadByteArrayFromSFTP(string imageLocationMemory)
        {
            var taskResult = await Task.Run(() =>
            {
                using (var client = new Renci.SshNet.SftpClient(Host, Port, Username, Password))
                {
                    client.Connect();
                    if (client.IsConnected)
                    {
                        client.ChangeDirectory(SFTPWorkingDirectory);
                        if (client.Exists(client.WorkingDirectory + "/" + imageLocationMemory))
                        {
                            return(client.ReadAllBytes(client.WorkingDirectory + "/" + imageLocationMemory));// imageLocationDisk == openFileDialog.FileName
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        OutputMessage = "Couldn't connect to SFTP server.";
                        return(null);
                    }
                }
            });

            return(taskResult);
        }