Click here to Skip to main content
15,888,035 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi i have a Filezilla server, i want to download files using active mode, but by default it takes passive.

C#
public FtpWebRequest GetRequest(string URI)
        {

            FtpWebRequest result = ((FtpWebRequest)(FtpWebRequest.Create(URI)));
          
            result.Credentials = GetCredentials();

            result.KeepAlive = false;

            if (isEnableSsl)
            {
                result.EnableSsl = true;

                ServicePointManager.
                            ServerCertificateValidationCallback = new
                               RemoteCertificateValidationCallback
                               (ValidateServerCertificate);
            }
            return result;

        }


and on filezilla server my logs showing PASV
here is my log on filezilla

C#
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> Connected, sending welcome message...
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> 220-FileZilla Server version 0.9.40 beta
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> 220 Please visit http://sourceforge.net/projects/filezilla/
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> USER tmp
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> 331 Password required for tmp
(000597)07-01-16 16:39:09 PM - (not logged in) (127.0.0.1)> PASS *******
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 230 Logged on
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> OPTS utf8 on
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 200 UTF8 mode enabled
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> PWD
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 257 "/" is current directory.
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> CWD CFM
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 250 CWD successful. "/CFM" is current directory.
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> TYPE I
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 200 Type set to I
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> PASV
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 227 Entering Passive Mode (127,0,0,1,248,44)
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> LIST
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 150 Connection accepted
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 226 Transfer OK
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> QUIT
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> 221 Goodbye
(000597)07-01-16 16:39:09 PM - tmp (127.0.0.1)> disconnected.




please help its urgent
Posted
Updated 7-Jan-16 1:53am
v2

Hi,

Please go through this article where explained about how to use active mode.

A network analysis of passive (EPSV or PASV) FTP connection. - Tips and tricks from a Developer Support perspective. - Site Home - MSDN Blogs[^]

you can go through this. I hope it will help you.
thanks
 
Share this answer
 
Set the FtpWebRequest.UsePassive Property[^] to false:
C#
result.UsePassive = false;
 
Share this answer
 
Could you please tell me how to implement this in C# ?
 
Share this answer
 
v2
Hi,

I am totally agree with @Jochen, you can use the UsePassive property to false.
Gets or sets the behavior of a client application's data transfer process.

Setting the UsePassive property to true sends the "PASV" command to the server. This command requests the server to listen on a data port and to wait for a connection rather than initiate one upon receipt of a transfer command.

For a description of the behaviors that are specified using UsePassive, see RFC 959, "File Transfer Protocol," Section 3.2, "Establishing Data Connections" and Section 4.1.2, "Transfer Parameter Commands," available at http://www.rfc-editor.org/.
C#
<pre lang="C#">
&lt;pre lang=&quot;C#&quot;&gt;using System.Net;
using System.IO;
    
String RemoteFtpPath = &amp;quot;ftp://ftp.csidata.com:21/Futures.20150305.gz&amp;quot;;
String LocalDestinationPath = &amp;quot;Futures.20150305.gz&amp;quot;;
String Username=&amp;quot;yourusername&amp;quot;;
String Password = &amp;quot;yourpassword&amp;quot;;
Boolean UseBinary = true; // use true for .zip file or false for a text file
Boolean UsePassive = false;
 
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(RemoteFtpPath);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.KeepAlive = true;
request.UsePassive = UsePassive;
request.UseBinary = UseBinary;
 
request.Credentials = new NetworkCredential(Username, Password);
 
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
 
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
 
using (FileStream writer = new FileStream(LocalDestinationPath, FileMode.Create))
{
 
    long length = response.ContentLength;
    int bufferSize = 2048;
    int readCount;
    byte[] buffer = new byte[2048];
 
    readCount = responseStream.Read(buffer, 0, bufferSize);
    while (readCount &amp;gt; 0)
    {
        writer.Write(buffer, 0, readCount);
        readCount = responseStream.Read(buffer, 0, bufferSize);
    }
}
 
reader.Close();
response.Close();&lt;/pre&gt;</pre>


Hope this will help you.
thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900