Some time ago, I studied FTP. If the FTP site does not support the PASV mode during FTP file transmission using FTPClient, but the intranet also has restrictions on the PORT mode, the tests failed multiple times, consider using the win api to convert the concept. Successfully implemented the platform call of WININET. DLL using C #. The following lists the functions used in it:
// The following two data structures are used in FTP implementation.
[StructLayout (LayoutKind. Sequential, CharSet = CharSet. Auto)]
Public class WIN32_FIND_DATA
{
Public UInt32 dwFileAttributes = 0;
Public FILETIME ftCreationTme;
Public FILETIME ftLastAccessTime;
Public FILETIME ftLastWriteTime;
Public UInt32 nFileSizeHigh = 0;
Public UInt32 nFileSizeLow = 0;
Public UInt32 dwReserved0 = 0;
Public UInt32 dwReserved1 = 0;
[Financialas (UnmanagedType. ByValTStr, SizeConst = 256)] public string cFileName = null;
[Financialas (unmanagedtype. byvaltstr, sizeconst = 14)] Public String calternatefilename = NULL;
};
[Structlayout (layoutkind. Sequential, charset = charset. Auto)]
Public class filetime
{
Public int dwlowdatetime = 0;
Public int dwhighdatetime = 0;
};
// Hosting and conversion of important functions in wininet. dll
[Dllimport ("wininet. dll", charset = charset. Auto)]
Public static extern bool internetgetlastresponseinfo (ref uint ulerror,
[Financialas (unmanagedtype. lptstr)] string strbuffer, ref uint ulbufferlength );
[Dllimport ("wininet. dll", charset = charset. Auto)]
Public static extern intptr internetopen (string strappname, ulong
Ulaccesstype, string strproxy, string strproxybypass, ulong ulflags );
[Dllimport ("wininet. dll", charset = charset. Auto)]
Public static extern bool internetfindnextfile (intptr hfind, [In, out] win32_find_data
Dirdata );
[Dllimport ("wininet. dll", charset = charset. Auto)]
Public static extern intptr internetconnect (intptr ulsession, string
Strserver, uint ulport, string struser, string strpassword, uint ulservice, uint ulflags,
Uint ulcontext );
[Dllimport ("wininet. dll", charset = charset. Auto)]
Public static extern bool internetgetconnectedstate (ref uint ulflags, uint
Ulreserved );
[Dllimport ("wininet. dll", charset = charset. Auto)]
Public static extern bool FtpSetCurrentDirectory (IntPtr ulSession, string
StrPath );
[DllImport ("wininet. dll", CharSet = CharSet. Auto)]
Public static extern IntPtr FtpFindFirstFile (IntPtr ulSession, string strPath
, [In, Out] WIN32_FIND_DATA dirData, ulong ulFlags, ulong ulContext );
[DllImport ("wininet. dll", CharSet = CharSet. Auto)]
Public static extern bool FtpGetFile (IntPtr ulSession, string strRemoteFile,
String strLocalFile, bool bolFailIfExist, ulong ulFlags, ulong ulInetFals, ulong
UlContext );
[DllImport ("wininet. dll", CharSet = CharSet. Auto)]
Public static extern bool FtpPutFile (IntPtr ulSession, string strLocalFile,
String strRemoteFile, ulong ulFlags, ulong ulContext );
[DllImport ("wininet. dll", CharSet = CharSet. Auto)]
Public static extern bool FtpDeleteFile (IntPtr ulSession, string strFileName );
[DllImport ("wininet. dll", CharSet = CharSet. Auto)]
Public static extern bool InternetCloseHandle (IntPtr ulSession );
There are many other functions in WININET. DLL. For details, see:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/wininet/wininet_reference.asp
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/wacle/archive/2004/09/22/113599.aspx