简体   繁体   English

无法使用FTP上传文件

[英]unable to upload files using FTP

i trying to upload pdf file to my websites Uploads folder but throwing below error.我试图将 pdf 文件上传到我的网站上传文件夹,但抛出以下错误。

My code is----我的代码是----

      try
         {
            string ftp = "ftp://ftp.MYSITE.com/Uploads/";
            byte[] fileBytes = null;
            string fileName = Path.GetFileName(FileUpload1.FileName);
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp +   fileName);
            request.Method = WebRequestMethods.Ftp.AppendFile;
            StreamReader sourceStream = new StreamReader("H:\\files\\User_Manual.pdf");
            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;
            request.Credentials = new NetworkCredential("USERNAME", "PASSWORD");
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(fileContents, 0, fileContents.Length);
            requestStream.Close();
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
            Console.WriteLine("Append status: {0}", response.StatusDescription);
            response.Close();
        }
        catch (WebException ex)
        {
            String status = ((FtpWebResponse)ex.Response).StatusDescription;
        }


**line " Stream requestStream = request.GetRequestStream();" throwing error.**

Error is------------错误是------------

The remote server returned an error: (550) File unavailable (eg, file not found, no access).远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问)。

Please help.请帮忙。

Update.更新。

Below is the complete solution for the same.以下是相同的完整解决方案。

http://complexquery.blogspot.in/2015/09/upload-file-using-ftp.html http://complexquery.blogspot.in/2015/09/upload-file-using-ftp.html

seems like permission issue.似乎是权限问题。 Instead of full path, use relative path..而不是完整路径,使用相对路径..

首先检查文件夹是否存在 {550 Permission Denied (or No such file or folder)} 然后检查文件夹权限以查看您是否确实对该文件夹具有写入权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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