I have implemented the ability to upload, download, delete, etc. using the FtpWebRequest
class in C#. That is fairly straight forward.
What I need to do now is support sending arbitrary FTP commands such as
quote SITE LRECL=132 RECFM=FB
or
quote SYST
Here's an example configuration straight from our app.config
:
<!-- The following commands will be executed before any uploads occur -->
<extraCommands>
<command>quote SITE LRECL=132 RECFM=FB</command>
</extraCommands>
I'm still researching how to do this using FtpWebRequest
. I'll probably try WebClient
class next. Anyone can point me in the right direction quicker? Thanks!
UPDATE:
I've come to that same conclusion, as of .NET Framework 3.5 FtpWebRequest
doesn't support anything except what's in WebRequestMethods.Ftp.*
. I'll try a third party app recommended by some of the other posts. Thanks for the help!
The
FtpWebRequest
won't help you as Thomas Levesque has said in his answer. You can use some third party solutions or the following, simplifiedTcpClient
based code which I have refactored from an answer written in Visual Basic:You can expect the following flow while getting through the FTP:
You can try our Rebex FTP component:
Use
sendCommand("SITE LRECL=242 BLKSIZE=0 RECFM=FB");
I don't think it can be done with
FtpWebRequest
... The only way to specify a FTP command is through theMethod
property, and the documentation states :SITE and SYST are not among the predefined options, so I guess you're stuck...
Don't waste time to try the
WebClient
class, it will give you even less flexibility thanFtpWebRequest
.However, there are plenty of third-party FTP implementation, open source or commercial, and I'm pretty sure some of them can handle custom commands...