Using the FtpCommand function in wininet.dll

  • Thread starter Thread starter gnanib
  • Start date Start date
G

gnanib

I am writing an FTP client in C# with the help of the functions
available in wininet.dll. I was able to get everything to work
except the use of the "FtpCommand" function. Basically I am trying
to issue the "ALLO" command to a server, but the ALLO command is not
availabe in wininet.dll. Therefore I have to use the FtpCommand.
I was wondering if anyone was able to successfully use this command in
C# to send out strings to a FTP server/client, and if so who to use
it. I keep getting error #87 back, which is an error indicating
incorrect parameters.
 
gnanib,

Errors of this type usally stem from the declaration. Check the
declaratio of FtpCommand that I've placed on Pinvoke.net and see if they
match.

If they do, then can you show how you are calling the API?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

gnanib said:
I am writing an FTP client in C# with the help of the functions
available in wininet.dll. I was able to get everything to work
except the use of the "FtpCommand" function. Basically I am trying
to issue the "ALLO" command to a server, but the ALLO command is not
availabe in wininet.dll. Therefore I have to use the FtpCommand.
I was wondering if anyone was able to successfully use this command in
C# to send out strings to a FTP server/client, and if so who to use
it. I keep getting error #87 back, which is an error indicating
incorrect parameters.
 
An identical message has been posted to csharphelp.com. I connected via
command line to both Microsoft and Linux FTP servers and ALLO seems to be a
bad command....

gnanib said:
I am writing an FTP client in C# with the help of the functions
available in wininet.dll. I was able to get everything to work
except the use of the "FtpCommand" function. Basically I am trying
to issue the "ALLO" command to a server, but the ALLO command is not
availabe in wininet.dll. Therefore I have to use the FtpCommand.
I was wondering if anyone was able to successfully use this command in
C# to send out strings to a FTP server/client, and if so who to use
it. I keep getting error #87 back, which is an error indicating
incorrect parameters.
 
I tried using your (Nicholas) declaration, but I still have problems.
Here is what I am doing. Please let me know what I am doing wrong:

// The declaration
DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool FtpCommand(IntPtr hConnect, bool
fExpectResponse, ulong ulFlags, string dwFlags, IntPtr dwContext, ref
IntPtr phFtpCommand);

// Declaration of variables to be used in function
IntPtr hInternetSession = new IntPtr(0); //handle to the Internet
session
IntPtr hInternetConnection = new IntPtr(0); //handle to the Internet
connection
IntPtr hInternetString = new IntPtr(0);
IntPtr hInternetTest = new IntPtr(0);

// hInternetSession and hInternetConnection are
// initialized when a connection to a server
// is made.
// I am not sure what to do with hInternetTest and
// and hInternetString.

// Use of function
FtpDll.FtpCommand(hInternetConnection, false, FTP_TRANSFER_TYPE_ASCII,
"ALLO 4156" , hInternetTest, ref hInternetString))
 
Back
Top