Reputation: 13
I want to transfer files that my Azure Web App creates to an FTP server outside the Azure network. All that I get is a 0 bytes file on the FTP and a "425 Can't open data connection" error on the Web App.
Is there a setting I'm missing on the Azure Web App or FTP Server? Same Web App on my local IIS Express works fine. The Web App uses ASP .NET MVC 5.
EDIT 1:
This is the code I'm using to send the file:
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(ftp + fileName);
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Credentials = new NetworkCredential(uid, pwd);
ftpRequest.ContentLength = fileBytes.Length;
Stream requestStream = ftpRequest.GetRequestStream();
requestStream.Write(fileBytes, 0, fileBytes.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)ftpRequest.GetResponse();
var status = response.StatusCode;
response.Close();
Acording to the MSDN the passive mode is the default one.
EDIT 2:
Enabling server logging this is the output:
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Created connection from <origin_ip> to <destination_ip>.
System.Net Information: 0 : [60572] Associating FtpWebRequest#23597360 with FtpControlStream#51898079
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [220 Microsoft FTP Service]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [USER <user>]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [331 Password required for <user>.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [PASS *]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [230 User <user> logged in.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [501 option not supported]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [PWD]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [257 "/" is current directory.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [TYPE I]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [200 Type set to I.]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [PASV]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [227 Entering Passive Mode (12,106,237,74,4,255).]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Sending command [STOR <file>]
System.Net Information: 0 : [60572] FtpControlStream#51898079 - Received response [425 Can't open data connection.]
System.Net Information: 0 : [60572] FtpWebRequest#23597360::(Releasing FTP connection#51898079.)
System.Net Error: 0 : [60572] Exception in FtpWebRequest#23597360::GetRequestStream - The remote server returned an error: (425) Can't open data connection..
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetRequestStream()
EDIT 3:
Another attempt:
System.Net Information: 0 : [58636] FtpWebRequest#9144495::.ctor(<ftp_address_and_file>)
System.Net Information: 0 : [58636] FtpWebRequest#9144495::GetRequestStream(Method=STOR.)
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Created connection from <origin_ip> to <destination_ip>.
System.Net Information: 0 : [58636] Associating FtpWebRequest#9144495 with FtpControlStream#57089836
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [220 Microsoft FTP Service]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [USER <user>]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [331 Password required for <user>.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [PASS *]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [230 User <user> logged in.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [501 option not supported]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [PWD]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [257 "/" is current directory.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [TYPE I]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [200 Type set to I.]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [PASV]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Received response [227 Entering Passive Mode (12,106,237,74,5,4).]
System.Net Information: 0 : [58636] FtpControlStream#57089836 - Sending command [STOR <file>]
System.Net Information: 0 : [58636] FtpWebRequest#9144495::(Releasing FTP connection#57089836.)
System.Net Error: 0 : [58636] Exception in FtpWebRequest#9144495::GetRequestStream - The operation has timed out..
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetRequestStream()
Upvotes: 0
Views: 5055
Reputation: 202292
The "Can't open data connection" is a message issued by FileZilla FTP server, when it cannot open data connection for a transfer.
What typically happens, when the client is using an active FTP mode behind a NAT or firewall and reports its internal IP address to the server, not knowing the server is not able to reach back to that IP address.
The easiest (and generally correct) solution is to use an FTP passive mode, instead of an active mode.
See my article on FTP connection modes to understand, what the active and passive mode means, and why everyone uses the passive mode nowadays.
Upvotes: 1