简体   繁体   English

“远程服务器返回错误:(501)参数或参数中的语法错误。”从Windows Azure上传到FTP时

[英]“The remote server returned an error: (501) Syntax error in parameters or arguments.” when uploading TO FTP FROM Windows Azure

I need to continuously upload a generated file from Azure to client's FTP but when I run the code below it gives me ... 我需要不断将生成的文件从Azure上传到客户端的FTP,但是当我运行下面的代码时它会给我...

The remote server returned an error: (501) Syntax error in parameters or arguments. 远程服务器返回错误:(501)参数或参数中的语法错误。

...also in Azure emulator it works fine. ...也在Azure模拟器中它工作正常。

This is a proof of concept purposes draft code, so I did not use Worker role, queue or blob etc. intentionally... 这是概念验证目的草案代码,所以我没有故意使用Worker角色,队列或blob等...

using System;
using System.IO;
using System.Net;
using System.Web;

namespace CloudWeb
{
    /// <summary>
    /// Summary description for Ftp
    /// </summary>
    public class Ftp : IHttpHandler
    {
        private const string FtpHost = "ftp://ftp.Host.com/App_Data/{0}";
        private const string FtpUserName = "UserName";
        private const string FtpPassword = "Password";
        private const string WarningImageFile = "images/status_warning.png";

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            UploadFtp(context.Server.MapPath(WarningImageFile));
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private static void UploadFtp(string source)
        {
            // read local file
            byte[] bFile = File.ReadAllBytes(source);

            // set ftp values
            var myFtp = (FtpWebRequest)WebRequest.Create(String.Format(FtpHost, Path.GetFileName(source)));
            myFtp.Method = WebRequestMethods.Ftp.UploadFile;
            myFtp.UsePassive = false;
            myFtp.UseBinary = true;
            myFtp.KeepAlive = true;
            myFtp.Credentials = new NetworkCredential(FtpUserName, FtpPassword);

            // upload file
            using (Stream clsStream = myFtp.GetRequestStream())
            {
                clsStream.Write(bFile, 0, bFile.Length);
                clsStream.Close();
                //clsStream.Dispose();
            }

            // ReSharper disable RedundantAssignment
            myFtp = null;
            // ReSharper restore RedundantAssignment
        }
    }
}

If you set UsePassive to false, then you need to make sure that the port for the command channel is open (ie, you need to define endpoints and access rules). 如果将UsePassive设置为false,则需要确保命令通道的端口已打开(即,您需要定义端点和访问规则)。 Unless there is a good reason to not use passive, you are far better off using passive. 除非有充分的理由不使用被动,否则你最好不要使用被动。

Erick 埃里克

暂无
暂无

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

相关问题 使用 PowerShell 连接到 Azure FTP 但在 C# 中工作时出现错误 501 - Error 501 when connecting to Azure FTP with PowerShell but works in C# Windows Azure Powershell部署错误 - “远程服务器返回了意外响应” - Windows Azure Powershell Deployment Error - “The remote server returned an unexpected response” PutBlock错误:远程服务器将文件上传到Azure时返回错误:(400)错误的请求 - PutBlock Error: The remote server returned an error: (400) Bad Request while uploading file to Azure Windows Azure存储版本升级到> 4会导致“远程服务器返回错误:(400)错误请求。” - Windows Azure Storage version upgrade to > 4 causes “The remote server returned an error: (400) Bad Request.” Running a C# FTP client against FTP server (active mode) from an Azure Function - “500 Syntax error, command unrecognized” - Running a C# FTP client against FTP server (active mode) from an Azure Function - “500 Syntax error, command unrecognized” 获取“远程服务器返回错误:(401) 未经授权。” 在 Azure DevOps 管道中创建发布时 - Getting "The remote server returned an error: (401) Unauthorized." when creating a release in Azure DevOps pipeline 删除Azure云中的Blob时远程服务器返回错误:(404)找不到 - When Delete the blob in azure cloud The remote server returned an error: (404) Not Found 尝试向azure表中添加行时得到“远程服务器返回错误:(409)冲突。” - Getting “The remote server returned an error: (409) Conflict.” when trying to add rows into azure table Azure“远程服务器返回错误:(530) 未登录。” - Azure “The remote server returned an error: (530) Not logged in.” “远程服务器返回错误:找不到”翻译器API Windows Phone 8 - “The remote server returned an error: NotFound” Translator API Windows phone 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM