简体   繁体   中英

upload audio recording to ftp

I need to upload audio files recorded from my application .I am unable to upload aac files to ftp. Here is my code to upload

FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(myftppath);

                ftp.Credentials = new NetworkCredential(username,password);

                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileStream fs = File.OpenRead(audioFilePath);

                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);

                fs.Close();

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();
                ftpstream.Flush();

The code works for uploading other files like txt,png,mp3 etc but not for aac files. Please help

Your code seems to be correct. You may try this,

  1. If you are running the app on simulator,check if your OS has permission to write file to ftp.
  2. Install your app on real device and try to upload using the same code.

If none works then find out the exact cause of error using try block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM