FtpWebRequest DeleteFile Problem

W

Waldy

Hi there,
I have written a service in VS2005 that downloads files from
an FTP site processes them and then deletes the files if successfully
processed. It all works fine when run in our test lab with an FTP site that
I setup on IIS. However, I have an issue at the customer site. Their FTP
server is on Linux, but I presume that is not an issue. What happened the
first time I ran it was that it deleted every other file. It just so
happened that there were files of about 60k and files of about 600k. The
small files were deleted, but the large ones were not. A WebException error
occured for the second, fourth e.t.c. files. When I ran it again, only the
larger files were left in the FTP folder, and only the first one was
deleted. I guess it may be sone sort of timing issue..
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi there,
              I have written a service in VS2005 that downloads files from
an FTP site processes them and then deletes the files if successfully
processed.  It all works fine when run in our test lab with an FTP sitethat
I setup on IIS.  However, I have an issue at the customer site.  Their FTP
server is on Linux, but I presume that is not an issue.  What happened the
first time I ran it was that it deleted every other file.  It just so
happened that there were files of about 60k and files of about 600k.  The
small files were deleted, but the large ones were not.  A WebException error
occured for the second, fourth e.t.c. files.  When I ran it again, onlythe
larger files were left in the FTP folder, and only the first one was
deleted.  I guess it may be sone sort of timing issue..

what says the exception?
Can you delete those files if you connect from the system ftp? maybe
you do not have permission to delete them
 
G

Goran Sliskovic

Waldy said:
Hi there,
I have written a service in VS2005 that downloads files from
an FTP site processes them and then deletes the files if successfully
processed. It all works fine when run in our test lab with an FTP site that
I setup on IIS. However, I have an issue at the customer site. Their FTP
server is on Linux, but I presume that is not an issue. What happened the
first time I ran it was that it deleted every other file. It just so
happened that there were files of about 60k and files of about 600k. The
small files were deleted, but the large ones were not. A WebException error
occured for the second, fourth e.t.c. files. When I ran it again, only the
larger files were left in the FTP folder, and only the first one was
deleted. I guess it may be sone sort of timing issue..

Can you please check exact exception? Is it maybe "bad sequence of
commands"?

Regards,
Goran
 
W

Waldy

Goran Sliskovic said:
Can you please check exact exception? Is it maybe "bad sequence of
commands"?

Hi Goran,
here is the error:

Exception: System.Net.WebException
Message: The remote server returned an error: (500) Syntax error, command
unrecognized.
Source: System
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetResponse()
 
P

Pavel Minaev

Waldy said:
Hi Goran,
here is the error:

Exception: System.Net.WebException
Message: The remote server returned an error: (500) Syntax error, command
unrecognized.
Source: System
at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
at System.Net.FtpWebRequest.RequestCallback(Object obj)
at System.Net.CommandStream.Abort(Exception e)
at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
at System.Net.FtpWebRequest.GetResponse()

It might help if you use a packet sniffer to get the actual log of the FTP
session - what commands go to the server, and what the responses to each
are.
 
G

Goran Sliskovic

Pavel Minaev said:
It might help if you use a packet sniffer to get the actual log of the FTP
session - what commands go to the server, and what the responses to each
are.

Yes, sniffer should reveal the problem. I had similar problem with UNIX
based system and FTPWebRequest. FTPWebRequest is cacheing connections to FTP
server and reuses the connection between commands. However, it resend
USER/PASS commands even on already connected and authorized connection (and
that is allowed according to standard) and UNIX server refuses it (it's an
embedded system). I end up with "bad sequence of commands", which is bit
different than what original poster gets.

Wireshark is free and powerfull sniffer, if we see the trace I guess will
find the problem.

Regards,
Goran
 
W

Waldy

Yes, sniffer should reveal the problem. I had similar problem with UNIX
based system and FTPWebRequest. FTPWebRequest is cacheing connections to
FTP
server and reuses the connection between commands. However, it resend
USER/PASS commands even on already connected and authorized connection
(and
that is allowed according to standard) and UNIX server refuses it (it's an
embedded system). I end up with "bad sequence of commands", which is bit
different than what original poster gets.

Hi Goran,
according to the trace, the response is returning 500
Unknown Command from a User request. So it appears to be the problem that
you talked about. How did you get round it.
 
G

Goran Sliskovic

Waldy said:
Hi Goran,
according to the trace, the response is returning 500
Unknown Command from a User request. So it appears to be the problem that
you talked about. How did you get round it.

Hi,
I gave up FTPWebRequest... Found some ugly FTP client code on the internet,
fixed few bugs and it's working now. You may try to set keepalive to false,
however that has some side effects (reconnect on every command).

Regards,
Goran
 
W

Waldy

Goran Sliskovic said:
You may try to set keepalive to false, however that has some side effects
(reconnect on every command).

Regards,
Goran

Good man! That's fixed it for me.
 
G

Goran Sliskovic

Waldy said:
Good man! That's fixed it for me.

Keep in mind that this will (probably) open/close TCP connection for every
command. If you have lot of commands (eg. files to delete) this is not free.
It will depend on the network infrastructure/project you are working on
whether this turns to real problem. You could possibly be cut by routers in
between as a result of false attack detection in some cases. It sucked for
me (connecting to embedded system over slow/high latency links). It is
relativly cheap to create interface and allow implementation to change. But
that depends on your project requirements.

Regards,
Goran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top