Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Setting transfer mode to binary

$
0
0
I am copying .wav phone recordings from a linux server to a windows share but the files are corrupted and unplayable after the copy is complete. I'm thinking this is because they are not being transferred as binary and I am unable to find a setting for this. The code is pretty simple:

ConnectionInfo info = new PasswordConnectionInfo(host, user, pwd);
        List<SftpFile> lst;
        using(SftpClient objSftp = new SftpClient(info))
        {
            objSftp.Connect();              
            lst = objSftp.ListDirectory(strSrc).ToList();
            foreach (SftpFile file in lst)
            {
                if (!file.IsDirectory)
                {
                    if (file.Name == "Test_Record.wav")
                    {
                        MemoryStream ms = new MemoryStream();
                        objSftp.DownloadFile(file.FullName, ms);

                        using (FileStream fs = new FileStream(strTarget + "\\" + file.Name, FileMode.Create, System.IO.FileAccess.Write))
                        {
                            byte[] bytes = new byte[ms.Length];
                            ms.Read(bytes, 0, (int)ms.Length);
                            fs.Write(bytes, 0, bytes.Length);
                            ms.Close();
                        }
                    }
                }
            }

            objSftp.Disconnect();
        }

Any ideas?

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>