C #] Use wininet. DLL to realize FTP function-Part One: function list ""

Source: Internet
Author: User
Tags filetime ftp file ftp site

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.