Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FtpWebRequest - The remote server returned an error, (425) can't open

Status
Not open for further replies.

fletchsod

Programmer
Dec 16, 2002
181
I'm a bit stumped on this problem and wonder if anyone of you encountered this situation and know of a workaround to it.

This FtpWebRequest function worked great on a Windows 2003 Server when connecting to ftp.kbb.com ftp server but when I ran this application on Windows 2008 Server, it failed. This Windows 2008 Server is a new server.

When I opened up Windows-Explorer and typed the ftp.kbb.com in there, Windows-Explorer was able to connect to KBB Ftp Server in Windows 2008 Server.

What could be the problem?

Code:
            //Initialize variables...
            System.IO.Stream oStream;
            System.IO.StreamReader oStreamReader;
            System.Net.FtpWebRequest oFtpWebRequest;
            System.Net.FtpWebResponse oFtpWebResponse;

                //Initialize variables...
                string sLine = "";
                ListViewItem oListViewItem = null;
                string sSubLine = "";
                Int32 iSubLine1 = 0;
                Int32 iSubLine2 = 0;
                string sFileSize = "";
                string sFileDate = "";
                string sFileName = "";

                //Setup the ListView setting (this.lvKbbFtpSite)...
                this.lvKbbFtpSite.MultiSelect = false;
                this.lvKbbFtpSite.View = System.Windows.Forms.View.Details;
                this.lvKbbFtpSite.Columns.Add("Name", 400, HorizontalAlignment.Left);
                this.lvKbbFtpSite.Columns.Add("Size", 200, HorizontalAlignment.Left);
                this.lvKbbFtpSite.Columns.Add("Date", 200, HorizontalAlignment.Left);

                //Setup the ftp configuration...
                oFtpWebRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(sFtpUrlAddress); // = System.Net.FtpWebRequest.(); // new System.Net.FtpWebRequest(); //= System.Net.FtpWebRequest.Create(sFtpUrlAddress);

                oFtpWebRequest.KeepAlive = false;
                oFtpWebRequest.UseBinary = true;
                oFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;
                oFtpWebRequest.UsePassive = false;
                //oFtpWebRequest.Timeout = 18000; //(5 * 60 * 60); //Timeout in milliseconds...

                //Connect to KBB ftp site...
                //#oFtpWebRequest.Credentials = new System.Net.NetworkCredential(sFtpUserName, sFtpPassword, sFtpUrlAddress);
                oFtpWebRequest.Credentials = new System.Net.NetworkCredential(sFtpUserName, sFtpPassword);

                //Get ftp result...
                oFtpWebResponse = (System.Net.FtpWebResponse)oFtpWebRequest.GetResponse();
                //Debug only...
                //MessageBox.Show("Ftp Status: " + oFtpWebResponse.StatusDescription.ToString());

                //Loop through the ftp response...
                oStream = oFtpWebResponse.GetResponseStream();
                oStreamReader = new System.IO.StreamReader(oStream, System.Text.Encoding.UTF8);

//Blah blah...

The error message said "The remote server returned an error: (425) can't open data connection".

The stack trace showed this...

--snip--
Stack Trace: at System.Net.FtpWebRequest.CheckError()
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetResponse()
at Server_Admin_App.frmPopupFtpExplorerDialog.ftnFrmViewListFillerWithFtpData(String sFtpUrlAddress, String sFtpUserName, String sFtpPassword)'
--snip--

Anyone know? Thanks...
 
sounds more like a server problem than a code problem, since it's the server that changed, not the code.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
That error means the data channel is blocked. If you're using an active connection use ports 20 & 21. If it's passive use 21 and 1024 and above. Also check your firewall settings.
 
Yesterday, I tried whitelisting the firewall setting for FTP ports with no luck.
 
Problem solved! In Windows 2008 Server, there are 2 different Firewall applications. One in control panel and the other in Administration Tools, they both are different application. So, that explained the confusion on why the FTP access is not working... The one in control panel, we just turned on the blocking notification (which allow us to unblock it) and that took care of hte problem.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top