I am working with the tutorial here: http://www.devtoolshed.com/content/c-download-file-progress-bar and I am receiving an UnauthorizedAccessException on the following line of code
using (Stream streamLocal = new FileStream(sPathToWriteFilesTo,
FileMode.Create, FileAccess.Write, FileShare.None))
{
//...
}
Perhaps it is something with permissions of the file I am trying to read? It is just a simple text file requested using FTP (instead of HTTP as the tutorial shows).
string sFtpToReadFilesFrom = "ftp://<user>:<pass>@mysite.tk/updates/App_Data/output_log.txt";
string sPathToWriteFilesTo = Application.StartupPath + "\\App_Data";
Uri url = new Uri(sFtpToReadFilesFrom);
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Timeout = 10000;
request.ReadWriteTimeout = 10000;
request.Method = WebRequestMethods.Ftp.GetFileSize;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
If anyone sees any immediate red flags with the FtpWebRequest please do let me know. I am primarily concerned with the UnauthorizedAccessException and how to fix that.
If you are on Win10 this line may cause errors:
string sPathToWriteFilesTo = Application.StartupPath + "\\App_Data";
Since one of updates you can't copy files from network location directly into some folders. Try downloads folder or some directly at C drive (eg c:\\TMP
).
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.