本文介绍了带有FTPwebrequest的FTPS错误550的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请帮助我解决以下错误

远程服务器返回错误550文件不可用的错误,例如找不到文件无法访问."

我正在尝试通过FTPS上传文件.
FTPS服务器不需要具有要上传的文件.
每次我都会上传新文件.
我们需要上传数百个文件dail.

但是我在uploadRequest.GetRequestStream()上遇到了以上错误.

提前谢谢..

我的代码如下:

Hi All,

Kindly help me with the below error

"the remote server returned an error 550 file unavailable e.g. file not found no access ."

I am trying to upload file through FTPS.
It is not required for the FTPS server to have the file which I am going to upload.
Everytime I will upload new new files.
100s of files we will need to upload dail.

however I am getting the above error at uploadRequest.GetRequestStream().

Thanks in advance..

My code is below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace ConsoleApplication1
{
    class Class1
    {
        public static void Main(string[] args)
        {
            Stream requestStream = null;
            FileStream fileStream = null;
            FtpWebResponse uploadResponse = null;
            try
            {
                Uri uploadUrl = new Uri("ftp://blaabll.blabala.com/folder/");
                string fileName = "c:\\sangeetha.xlsx";
                FtpWebRequest uploadRequest =
                 (FtpWebRequest)WebRequest.Create(uploadUrl + @"/" + fileName);
                uploadRequest.Method = WebRequestMethods.Ftp.UploadFile              //Since the FTP you are downloading to is secure, send
                //in user name and password to be able upload the file
                ICredentials credentials = new NetworkCredential(user, password);
                uploadRequest.Credentials = credentials;
                //UploadFile is not supported through an Http proxy
                //so we disable the proxy for this request.
                uploadRequest.Proxy = null;
                //uploadRequest.UsePassive = false; <--found from another forum and did not make a difference
           <b>      requestStream = uploadRequest.GetRequestStream()</b> 
                fileStream = File.Open(fileName, FileMode.Open);
                byte[] buffer = new byte[1024];
                int bytesRead;
                while (true)
                {
                    bytesRead = fileStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                        break;
                    requestStream.Write(buffer, 0, bytesRead);
                }
                //The request stream must be closed before getting
                //the response.
                requestStream.Close();
                uploadResponse =
                  (FtpWebResponse)uploadRequest.GetResponse();
            }
            catch (UriFormatException ex)
            {
             //   ErrorsHappened.Items.Add("Error: " + ex.Message);
            }
            catch (IOException ex)
            {
              // ErrorsHappened.Items.Add("Error: " + ex.Message);
            }
            catch (WebException ex)
            {
                //ErrorsHappened.Items.Add("Error: " + ex.Message);
            }
            finally
            {
                if (uploadResponse != null)
                    uploadResponse.Close();
                if (fileStream != null)
                    fileStream.Close();
                if (requestStream != null)
                    requestStream.Close();
            }
        }
    }
}

推荐答案


这篇关于带有FTPwebrequest的FTPS错误550的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 22:38