I’am trying to create azure function that would be able to send some randomly generated csv files to FTP server on azure VM. So i created an Function that does that, but in local environment. Everything was looking good, so i decided to deploy it. After deploying the function, i’ve got some strange errors.
I’m generating 2 folders and at the end the file itself. Strange was that the function created 2 folders but failed on creating file. The Error was:
The remote server returned an error: (500) Syntax error, command unrecognized.
Here is my code for sending files
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{folderPath}/{uploadFileName}");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(user, password);
using (MemoryStream newFileStream = new MemoryStream(Encoding.UTF8.GetBytes(uploadFileContent ?? "")))
{
using (Stream requestStream = request.GetRequestStream())
{
await newFileStream.CopyToAsync(requestStream);
_logger.LogError("File uploaded successfully.");
return true;
}
}
I’ve read through the entire internet, and i still haven’t found the answer.
I’ve already tried changing these settings:
- request.UsePassive = true/false
- request.Timeout = -1
- request.UseBinary = true/false
I’ve also check the ftp path that i’m sending to, and it looks fine:
“ftp://{ADDRESS}/{FOLDER1NAME}/FOLDER2NAME/{FILENAME}.csv”
The FTP Server is configured on Azure VM (Linux, port 21 is open for all)
Azure Function is deployed on Windows.
After executing code,i’m able to login in to FTP server using CMD and i can see created folders.
Important Update
I’ve tried to use publicly accesible ftp test server, and it worked!
Any idea what could it be in VM Machine context? Some settings are blocking incoming files?