cf2000 发表于 2015-5-29 12:01:53

C#]Use wininet.dll to realize ftp function-Part One :function list《转》

  前段时间研究FTP,利用FTPClient在进行FTP文件传输时如果FTP站点不支持PASV模式,而内网对PORT模式也有限制的时候,多次测试未能成功,转换思路,考虑用WIN API。成功地实现了用C#对WININET.DLL的平台调用,下面将里面用到的函数列表如下:
//下面两个是在实现FTP过程中用到的两个数据结构

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;
    public string cFileName=null;
    public string cAlternateFileName=null;
};
  

public class FILETIME
{
   public int dwLowDateTime=0;
   public int dwHighDateTime=0;
};

//以下是对WININET.DLL中的重要函数的托管转换

public static extern bool InternetGetLastResponseInfo(ref uint ulError,
    string strBuffer, ref uint ulBufferLength);
  
public static extern IntPtr InternetOpen(string strAppName, ulong
   ulAccessType, string strProxy, string strProxyBypass, ulong ulFlags);


public static extern bool InternetFindNextFile(IntPtr hFind, WIN32_FIND_DATA
   dirData);
  
public static extern IntPtr InternetConnect(IntPtr ulSession, string
   strServer, uint ulPort, string strUser, string strPassword, uint ulService, uint ulFlags,
   uint ulContext);
  
public static extern bool InternetGetConnectedState(ref uint ulFlags, uint
   ulReserved);
  
public static extern bool FtpSetCurrentDirectory(IntPtr ulSession, string
   strPath);
  
public static extern IntPtr FtpFindFirstFile(IntPtr ulSession, string strPath
   , WIN32_FIND_DATA dirData, ulong ulFlags, ulong ulContext);
  
public static extern bool FtpGetFile(IntPtr ulSession, string strRemoteFile,
   string strLocalFile, bool bolFailIfExist, ulong ulFlags, ulong ulInetFals, ulong
   ulContext);
  
public static extern bool FtpPutFile(IntPtr ulSession, string strLocalFile,
   string strRemoteFile, ulong ulFlags, ulong ulContext);
  
public static extern bool FtpDeleteFile(IntPtr ulSession, string strFileName);
  
public static extern bool InternetCloseHandle(IntPtr ulSession);

在WININET.DLL中还有很多其他功能的函数,详细内容请看:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/wininet_reference.asp
  
  本文来自CSDN博客,转载请标明出处:http://blog.iyunv.com/wacle/archive/2004/09/22/113599.aspx
页: [1]
查看完整版本: C#]Use wininet.dll to realize ftp function-Part One :function list《转》