'Trying to connect to an FTP server from Azure App service
I am trying to upload/download some files from Azure VM directly through a Azure App service, but the app returns this error:
System.Net.WebException: The remote server returned an error: (501) Syntax error in parameters or arguments.
I am using blazor and this is the code from the that I use to upload:
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://xxx.xxx.xxx.xxx/dir/file.conf");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = false;
request.Credentials = new NetworkCredential("xxxx", "xxxx");
// convert contents to byte.
byte[] fileContents = Encoding.ASCII.GetBytes(str); ;
request.ContentLength = fileContents.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(fileContents, 0, fileContents.Length);
}
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine($"Upload File Complete, status {response.StatusDescription}");
}
}
If I do try from my PC it works properly.
Solution 1:[1]
- There could be several reasons for the FTP issue, the exact error message may provide some pointers.
- Azure App Service supports connecting via both Active and Passive mode. Passive mode is preferred because your deployment machines are usually behind a firewall.
- If you set UsePassive to false, then you need to make sure that the port for the command channel is open (i.e., you need to define endpoints and access rules). Unless there is a good reason to not use passive, you are far better off using passive.
- Refer this document for more information:
Deploy your app to Azure App Service using FTP/S - You can also copy files directly from Kudu console to local: http://yourwebappname.scm.azurewebsites.net/ (Add'scm' to the default WebApps mentioned above)
- Go to the cmd button and look in the site/wwwroot folder for your project files.
- You could also use VS team explorer to clone the WebApp from Azure App Service to your local Visual Studio (VS).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SuryasriKamini-MT |
