FtpWebRequest usage

Hi,

I am trying to use FtpWebRequest and my program works, but very slow. I suppose it is bacuse FtpWebRequest opens connection every time when I try to get some information. So if I want to get full directory listing program creates instance of FtpWebRequest class tree times to make the following request Methods: ListDirectoryDetails, GetFileSize, GetDateTimestamp. (well, it's possible to get file size from directory list and this gives 33% less in connections number, but I want to use framework as much as I can - this is the purpose of FW, right ).
I took this approach from 'FTP Explorer Technology Sample'.
So, I am wondering if there are any ways to speed up that process FtpWebRequest has a KeepAlive property, but if I set it to true and try to use the same instace to get size (GetFileSize) and then modification date (GetDateTimestamp) I receive exception when try to assign Method property.

I suspect that I mess something important. ;)

regards,
Roman.


Answer this question

FtpWebRequest usage

  • dib56115

    This is what I used to trace my example:

    < xml version="1.0" >
    <configuration>
    <system.diagnostics>
    <sources>
    <source name="System.Net">
    <listeners>
    <add name="1"/>
    </listeners>
    </source>
    <source name="System.Net.Sockets">
    <listeners>
    <add name="1"/>
    </listeners>
    </source>
    <source name="System.Net.Cache">
    <listeners>
    <add name="1"/>
    </listeners>
    </source>
    </sources>
    <switches>
    <add name="System.Net" value="Verbose"/>
    <add name="System.Net.Sockets" value="Verbose" />
    <add name="System.Net.Cache" value="Verbose" />
    </switches>
    <sharedListeners>
    <add name="1" type="System.Diagnostics.TextWriterTraceListener" initializeData="g:\tmp\ft-sys.log" traceOutputOptions="DateTime"/>
    </sharedListeners>
    </system.diagnostics>
    </configuration>

    change filename to direct output to and enjoy.

  • ElisabetdW

    Are you sure there are multiple connections You need to use different instances of FTPWebRequest alright but the underlying connections are pooled. You could use a network monitor or System.Net trace to
    figure out how many connections are actually being used. The number of FTPWebRequest instances are not always equal to the number of
    connections used. PLease use the
    http://blogs.msdn.com/dgorti to get a trace file and it will show you how many connections are being open. You should also use a network monitor to clearly see what is going on the wire.

  • pankaj sharma103086

    I got mine to work prior to this post but thank you anyways. You do not use a <trace> tag
  • Jan Ferneman

    As you can see. I took this code from MSDN docs and made some small modifications. And, finally, it works...


    Roman.

  • njf

    On you site you have an example for a config file with trace enabled...

    <trace autoflush="true" />
    <sources>
    <source name="System.Net" maxdatasize="1024">
    <listeners>
    <add name="MyTraceFile"/>
    </listeners>
    </source>
    </sources>

    <sharedListeners>
    <add
    name="MyTraceFile"
    type="System.Diagnostics.TextWriterTraceListener"
    initializeData="System.Net.trace.log"
    />
    </sharedListeners>

    <switches>
    <add name="System.Net" value="Verbose" />
    </switches>

    Where is the </trace> or do we not need one The example on msdn has the closing tag, yours doesn't.

  • FtpWebRequest usage