kexx kexx - 1 month ago 14
Vb.net Question

Uploading file with FtpWebRequest from an azure hosted application to an external ftp site


UPDATE: I found out that it is not an issue with azure rather the
other party who are actually doing white-listing on incoming
connection.



I implemented a service, which open and ftp connection to upload a file to a remote FTP server. The code works perfectly (!) running on my desktop, however if I publish it to the azure hosting cloud and execute with exactly the same parameters I get WebException with the message 'The remote server returned an error: (530) Not logged in.' I haven't found any relevant setting in the azure console. I also tried different setting like on/off keep-alive and passive, but the result are the same. Do you guys have an idea what could be the problem?

The code for reference:

Dim request As FtpWebRequest

request = TryCast(WebRequest.Create($"ftp://{_host}/inventory/{_uploadFilename}"), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(_username, _password)
request.UsePassive = True
request.UseBinary = True
request.KeepAlive = False

Using fs As FileStream = File.OpenRead(_fileName)
Dim buffer As Byte() = New Byte(fs.Length - 1) {}
fs.Read(buffer, 0, buffer.Length)
fs.Close()
Dim requestStream As Stream = request.GetRequestStream()
requestStream.Write(buffer, 0, buffer.Length)
requestStream.Flush()
requestStream.Close()


Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
Return Ok($"Remote server response: {response.StatusDescription}")

End Using

Answer

I found out that it is not an issue with azure rather the other party who are actually doing white-listing on incoming connection.

Comments