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);
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?