csharp: using wininet.dll
/// <summary>
/// Windows Embedded CE 6.0 R3 WinInet Functions
/// https://technet.microsoft.com/zh-cn/aa914184
/// Windows WinINet Functions
/// https://technet.microsoft.com/zh-cn/windows/aa385473(v=vs.71)
///
/// </summary>
public class NetUtil
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(int Description, int ReservedValue); /// <summary>
/// 用于检查网络是否可以连接互联网,true表示连接成功,false表示连接失败
/// </summary>
/// <returns></returns>
public static bool IsConnectInternet()
{
int Description = ;
return InternetGetConnectedState(Description, );
} [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class WIN32_FIND_DATA
{
public UInt32 dwFileAttributes = ;
public FILETIME ftCreationTme;
public FILETIME ftLastAccessTime;
public FILETIME ftLastWriteTime;
public UInt32 nFileSizeHigh = ;
public UInt32 nFileSizeLow = ;
public UInt32 dwReserved0 = ;
public UInt32 dwReserved1 = ;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = )]
public string cFileName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = )]
public string cAlternateFileName = null;
}; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class FILETIME
{
public int dwLowDateTime = ;
public int dwHighDateTime = ;
}; //以下是对WININET.DLL中的重要函数的托管转换
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool InternetGetLastResponseInfo(ref uint ulError,
[MarshalAs(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); /// <summary>
//STRUCTURE to hold the directory information - implemented as a class
/// <summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class FileData
{
public int fileAttributes = ;
// creationTime was embedded FILETIME structure
public int creationTime_lowDateTime = ;
public int creationTime_highDateTime = ;
// lastAccessTime was embedded FILETIME structure
public int lastAccessTime_lowDateTime = ;
public int lastAccessTime_highDateTime = ;
// lastWriteTime was embedded FILETIME structure
public int lastWriteTime_lowDateTime = ;
public int lastWriteTime_highDateTime = ;
public int nFileSizeHigh = ;
public int nFileSizeLow = ;
public int dwReserved0 = ;
public int dwReserved1 = ;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = )]
public String fileName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = )]
public String alternateFileName = null;
} //end of class FileDate /// <summary>
/// Class FtpDll implements the 'wininet.dll' api for FTP connection over firewalls!
/// </summary>
public class FtpDll
{
//DECLARATIONS
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern uint SetLastError(uint uiErrorCode);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern uint GetLastError();
[DllImport("wininet.dll", CharSet = CharSet.Auto)]
public static extern bool InternetGetLastResponseInfo(ref uint ulError, [MarshalAs(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 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 FtpGetCurrentDirectory(IntPtr ulSession, string strPath, ulong ulBuffLength);
[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] FileData dirData, ulong ulFlags, ulong ulContext); //returns handle for InternetFindNextFile
// [DllImport("wininet.dll", CharSet = CharSet.Auto)]
// public static extern bool InternetFindNextFile(ulong ulFindFirst, [In, Out] FileData dirData);
[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 FtpRenameFile(IntPtr ulSession, string strExisting, string strNew);
[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); //CONSTANTS - there are plenty more of these, only the important ones are here!
//InternetOpen:aul_AccessType flags
public const uint OPEN_TYPE_PRECONFIG = ;
public const uint OPEN_TYPE_DIRECT = ;
public const uint OPEN_TYPE_GATEWAY = ;
public const uint OPEN_TYPE_PROXY = ;
//Ports
public const uint INVALID_PORT_NUMBER = ;
public const uint DEFAULT_FTP_PORT = ;
public const uint DEFAULT_GOPHER_PORT = ;
public const uint DEFAULT_HTTP_PORT = ;
public const uint DEFAULT_HTTPS_PORT = ;
public const uint DEFAULT_SOCKS_PORT = ;
//Service/Command types
public const uint SERVICE_FTP = ;
public const uint SERVICE_GOPHER = ;
public const uint SERVICE_HTTP = ;
//Internet connection flags
public const uint CONNECTION_MODEM = ;
public const uint CONNECTION_LAN = ;
public const uint CONNECTION_PROXY = ;
public const uint CONNECTION_MODEM_BUSY = ;
//FTP transfer flags
public const uint FTP_TRANSFER_TYPE_ASCII = ;
public const uint FTP_TRANSFER_TYPE_BINARY = ; //VARIABLES
IntPtr hInternetSession = new IntPtr(); //handle to the Internet session
IntPtr hInternetConnection = new IntPtr(); //handle to the Internet connection
uint intErrorValue = ; //error value
string strErrorText = "";
FileData myFileData;
bool bolDebug = true; public FtpDll()
{ //constructor
myFileData = new FileData(); //instance the FileData class to hold the dir info
} public void funIOpen()
{
string strProxy = "";
string strProxyBypass = "";
try
{
funClearError(); //clear the 'last error' value
hInternetSession = FtpDll.InternetOpen("FTPTest", FtpDll.OPEN_TYPE_DIRECT, strProxy, strProxyBypass, );
if (funGetError())
{
if (intErrorValue != ) //hum... seem to always get 127 back!?!
throw new Exception("funIOpen failed, error value: " + intErrorValue + " - " + strErrorText);
}
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public bool funIConnected()
{ //check if we are connected
bool bolOnLine = false;
try
{
if (hInternetConnection != IntPtr.Zero)
{ //we have an internet connection handle
uint uintFlags = ;
funClearError(); //clear the 'last error' value
FtpDll.InternetGetConnectedState(ref uintFlags, ); //ask for the connection status
//if (uintFlags & FtpDll.CONNECTION_LAN > 0) //so long as we have a connection value...
if (uintFlags > ) //so long as we have a connection value...
bolOnLine = true;
if (funGetError())
throw new Exception("funIConnected failed, error value: " + intErrorValue + " - " + strErrorText);
}
else
throw new Exception("funIConnected failed; need to establish an Internet session first!");
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
return bolOnLine;
} public void funIConnect()
{ //connect using default values
try
{
string strHostURL = "ftp.microsoft.com";
string strUser = "anonymous";
string strPW = "fred@test.com";
funIConnect(strHostURL, strUser, strPW);
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public void funIConnect(string strHostURL, string strUser, string strPW)
{
if (hInternetSession == IntPtr.Zero)
funIOpen(); //we always need a session first
try
{
funClearError(); //make sure we are clean before starting to connect
hInternetConnection = FtpDll.InternetConnect(hInternetSession, strHostURL, FtpDll.DEFAULT_FTP_PORT, strUser, strPW, FtpDll.SERVICE_FTP, , );
if (funGetError())
throw new Exception("funIConnect failed, error value: " + intErrorValue + " - " + strErrorText);
if (hInternetConnection == IntPtr.Zero) //if the handle is still zero....
throw new Exception("Failed to get a handle in funIConnect - no error code given!");
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public void funFTPChangeDir(string strDir)
{
try
{
if (!funIConnected())
throw new Exception("Please connect to FTP host first!");
funClearError(); //clear the 'last error' value
FtpDll.FtpSetCurrentDirectory(hInternetConnection, strDir);
if (funGetError())
throw new Exception("funFTPChangeDir failed, error value: " + intErrorValue + " - " + strErrorText);
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public string funFTPFirstFile(string strPath)
{
string strFileName = "";
try
{
if (!funIConnected())
throw new Exception("Please connect to FTP host first!");
funClearError(); //clear the 'last error' value
FtpDll.FtpFindFirstFile(hInternetConnection, strPath, myFileData, , );
if (funGetError())
throw new Exception("funFTPFirstFile failed, error value: " + intErrorValue + " - " + strErrorText);
strFileName = myFileData.fileName;
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
return strFileName;
} public void funFTPGetFile(string strRemoteFile, string strLocalFile)
{
try
{
if (!funIConnected())
throw new Exception("Please connect to FTP host first!");
funClearError(); //clear the 'last error' value
FtpDll.FtpGetFile(hInternetConnection, strRemoteFile, strLocalFile, false, , , );
if (funGetError())
throw new Exception("funFTPGet failed, error value: " + intErrorValue + " - " + strErrorText);
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public void funFTPPutFile(string strLocalFile, string strRemoteFile)
{
try
{
if (!funIConnected())
throw new Exception("Please connect to FTP host first!");
funClearError(); //clear the 'last error' value
FtpDll.FtpPutFile(hInternetConnection, strLocalFile, strRemoteFile, , );
if (funGetError())
throw new Exception("funFTPPut failed, error value: " + intErrorValue + " - " + strErrorText);
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public void funFTPDeleteFile(string strFileName)
{
try
{
if (!funIConnected())
throw new Exception("Please connect to FTP host first!");
funClearError(); //clear the 'last error' value
FtpDll.FtpDeleteFile(hInternetConnection, strFileName);
if (funGetError())
{
if (intErrorValue == )
{ //special case? the function seems otherwise OK?!?!?!
if (bolDebug) Console.WriteLine("funFTPDeleteFile succeeded, but returned an error code 2 - ignored!");
}
else
throw new Exception("funFTPDeleteFile failed, error value: " + intErrorValue + " - " + strErrorText);
}
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
} public void funFTPDisconnect()
{
if (hInternetSession != IntPtr.Zero)
{ //if and only if we have a session...
try
{
funClearError(); //clear the 'last error' value
FtpDll.InternetCloseHandle(hInternetSession);
if (funGetError())
throw new Exception("funFTPDisconnect failed, error value: " + intErrorValue + " - " + strErrorText);
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
throw e; //pass this exception back to the caller
}
}
hInternetSession = IntPtr.Zero; //reset this handle?
} public void funClearError()
{ //clear the 'last error' value
FtpDll.SetLastError();
} public bool funGetError()
{ //return true if an error found
intErrorValue = FtpDll.GetLastError();
switch (intErrorValue)
{
case : //ERROR_PROC_NOT_FOUND
strErrorText = "The specified procedure could not be found.";
break;
case : //ERROR_FILE_NOT_FOUND
strErrorText = "The system cannot find the file specified.";
break;
case : //ERROR_NO_MORE_FILES
strErrorText = "There are no more files.";
break;
case : //ERROR_INVALID_NAME
strErrorText = "The filename, directory name, or volume label syntax is incorrect.";
break;
case : //ERROR_INTERNET_EXTENDED_ERROR
try
{
string strExtErrorText = "";//to hold the ExtErrorText
uint uiExtErrorTextLength = ;//start as zero length
FtpDll.InternetGetLastResponseInfo(ref intErrorValue, strExtErrorText, ref uiExtErrorTextLength);
if (uiExtErrorTextLength > )
{//indicasting the length of the message to collect
strExtErrorText += new string(' ', (int)uiExtErrorTextLength);//beef up the string buffer
FtpDll.InternetGetLastResponseInfo(ref intErrorValue, strExtErrorText, ref uiExtErrorTextLength);
if (uiExtErrorTextLength > )
strErrorText = "The server has returned an extended error: " + strExtErrorText;
else
strErrorText = "The server has returned an extended error, but the text can not be recovered at all?!?.";
}
else
strErrorText = "The server has returned an extended error, but the text can not be recovered!?.";
}
catch (Exception e)
{
if (bolDebug) Console.WriteLine(e.Message);
}
break;
case : //ERROR_FTP_DROPPED
strErrorText = "The FTP operation was not completed because the session was aborted.";
break;
case : //ERROR_FTP_TRANSFER_IN_PROGRESS
strErrorText = "The requested operation cannot be made on the FTP session handle because an operation is already in progress.";
break;
case : //ERROR_GOPHER_ATTRIBUTE_NOT_FOUND
strErrorText = "The requested attribute could not be located.";
break;
case : //ERROR_GOPHER_DATA_ERROR
strErrorText = "An error was detected while receiving data from the Gopher server.";
break;
case : //ERROR_GOPHER_END_OF_DATA
strErrorText = "The end of the data has been reached.";
break;
case : //ERROR_GOPHER_INCORRECT_LOCATOR_TYPE
strErrorText = "The type of the locator is not correct for this operation.";
break;
case : //ERROR_GOPHER_INVALID_LOCATOR
strErrorText = "The supplied locator is not valid.";
break;
case : //ERROR_GOPHER_NOT_FILE
strErrorText = "The request must be made for a file locator.";
break;
case : //ERROR_GOPHER_NOT_GOPHER_PLUS
strErrorText = "The requested operation can only be made against a Gopher+ server, or with a locator that specifies a Gopher+ operation.";
break;
case : //ERROR_GOPHER_PROTOCOL_ERROR
strErrorText = "An error was detected while parsing data returned from the Gopher server.";
break;
case : //ERROR_GOPHER_UNKNOWN_LOCATOR
strErrorText = "The locator type is unknown.";
break;
case : //ERROR_HTTP_DOWNLEVEL_SERVER
strErrorText = "The server did not return any headers.";
break;
case : //ERROR_HTTP_HEADER_ALREADY_EXISTS
strErrorText = "The header could not be added because it already exists.";
break;
case : //ERROR_HTTP_HEADER_NOT_FOUND
strErrorText = "The requested header could not be located.";
break;
case : //ERROR_HTTP_INVALID_HEADER
strErrorText = "The supplied header is invalid.";
break;
case : //ERROR_HTTP_INVALID_QUERY_REQUEST
strErrorText = "The request made to HttpQueryInfo is invalid.";
break;
case : //ERROR_HTTP_REDIRECT_FAILED
strErrorText = "The redirection failed because either the scheme changed (HTTP to FTP) or all attempts made to redirect failed.";
break;
case : //ERROR_HTTP_REDIRECT_NEEDS_CONFIRMATION
strErrorText = "The redirection requires user confirmation.";
break;
case : //ERROR_HTTP_INVALID_SERVER_RESPONSE
strErrorText = "The server response could not be parsed.";
break;
case : //ERROR_INTERNET_ASYNC_THREAD_FAILED
strErrorText = "The application could not start an asynchronous thread.";
break;
case : //ERROR_INTERNET_BAD_OPTION_LENGTH
strErrorText = "The length of an option supplied to InternetQueryOption or InternetSetOption is incorrect for the type of option specified.";
break;
case : //ERROR_INTERNET_BAD_AUTO_PROXY_SCRIPT
strErrorText = "There was an error in the automatic proxy configuration script.";
break;
case : //ERROR_INTERNET_BAD_REGISTRY_PARAMETER
strErrorText = "A required registry value was located but is an incorrect type or has an invalid value.";
break;
case : //ERROR_INTERNET_CANNOT_CONNECT
strErrorText = "The attempt to connect to the server failed.";
break;
case : //ERROR_INTERNET_CHG_POST_IS_NON_SECURE
strErrorText = "The application is posting and attempting to change multiple lines of text on a server that is not secure.";
break;
case : //ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED
strErrorText = "The server is requesting client authentication.";
break;
case : //ERROR_INTERNET_CLIENT_AUTH_NOT_SETUP
strErrorText = "Client authorization is not set up on this computer.";
break;
case : //ERROR_INTERNET_CONNECTION_ABORTED
strErrorText = "The connection with the server has been terminated.";
break;
case : //ERROR_INTERNET_CONNECTION_RESET
strErrorText = "The connection with the server has been reset.";
break;
case : //ERROR_INTERNET_DIALOG_PENDING
strErrorText = "Another thread has a password dialog in progress.";
break;
case : //ERROR_INTERNET_DISCONNECTED
strErrorText = "The Internet connection has been lost.";
break;
case : //ERROR_INTERNET_FAILED_DUETOSECURITYCHECK
strErrorText = "The function failed due to a security check.";
break;
case : //ERROR_INTERNET_FORCE_RETRY
strErrorText = "The Win32 Internet function needs to redo the request.";
break;
case : //ERROR_INTERNET_HANDLE_EXISTS
strErrorText = "The request failed because the handle already exists.";
break;
case : //ERROR_INTERNET_HTTP_TO_HTTPS_ON_REDIR
strErrorText = "The application is moving from a non-SSL to an SSL connection because of a redirect.";
break;
case : //ERROR_INTERNET_HTTPS_TO_HTTP_ON_REDIR
strErrorText = "The application is moving from an SSL to an non-SSL connection because of a redirect.";
break;
case : //ERROR_INTERNET_INCORRECT_FORMAT
strErrorText = "The format of the request is invalid.";
break;
case : //ERROR_INTERNET_INCORRECT_HANDLE_STATE
strErrorText = "The requested operation cannot be carried out because the handle supplied is not in the correct state.";
break;
case : //ERROR_INTERNET_INCORRECT_HANDLE_TYPE
strErrorText = "The type of handle supplied is incorrect for this operation.";
break;
case : //ERROR_INTERNET_INCORRECT_PASSWORD
strErrorText = "The request to connect and log on to an FTP server could not be completed because the supplied password is incorrect.";
break;
case : //ERROR_INTERNET_INCORRECT_USER_NAME
strErrorText = "The request to connect and log on to an FTP server could not be completed because the supplied user name is incorrect.";
break;
case : //ERROR_INTERNET_INSERT_CDROM
strErrorText = "The request requires a CD-ROM to be inserted in the CD-ROM drive to locate the resource requested.";
break;
case : //ERROR_INTERNET_INTERNAL_ERROR
strErrorText = "An internal error has occurred.";
break;
case : //ERROR_INTERNET_INVALID_CA
strErrorText = "The function is unfamiliar with the Certificate Authority that generated the server's certificate.";
break;
case : //ERROR_INTERNET_INVALID_OPERATION
strErrorText = "The requested operation is invalid.";
break;
case : //ERROR_INTERNET_INVALID_OPTION
strErrorText = "A request to InternetQueryOption or InternetSetOption specified an invalid option value.";
break;
case : //ERROR_INTERNET_INVALID_PROXY_REQUEST
strErrorText = "The request to the proxy was invalid.";
break;
case : //ERROR_INTERNET_INVALID_URL
strErrorText = "The URL is invalid.";
break;
case : //ERROR_INTERNET_ITEM_NOT_FOUND
strErrorText = "The requested item could not be located.";
break;
case : //ERROR_INTERNET_LOGIN_FAILURE
strErrorText = "The request to connect and log on to an FTP server failed.";
break;
case : //ERROR_INTERNET_MIXED_SECURITY
strErrorText = "The content is not entirely secure. Some of the content being viewed may have come from unsecured servers.";
break;
case : //ERROR_INTERNET_NAME_NOT_RESOLVED
strErrorText = "The server name could not be resolved.";
break;
case : //ERROR_INTERNET_NEED_UI
strErrorText = "A user interface or other blocking operation has been requested.";
break;
case : //ERROR_INTERNET_NO_CALLBACK
strErrorText = "An asynchronous request could not be made because a callback function has not been set.";
break;
case : //ERROR_INTERNET_NO_CONTEXT
strErrorText = "An asynchronous request could not be made because a zero context value was supplied.";
break;
case : //ERROR_INTERNET_NO_DIRECT_ACCESS
strErrorText = "Direct network access cannot be made at this time.";
break;
case : //ERROR_INTERNET_NOT_PROXY_REQUEST
strErrorText = "The request cannot be made via a proxy.";
break;
case : //ERROR_INTERNET_OPERATION_CANCELLED
strErrorText = "The operation was canceled, usually because the handle on which the request was operating was closed before the operation completed.";
break;
case : //ERROR_INTERNET_OPTION_NOT_SETTABLE
strErrorText = "The requested option cannot be set, only queried.";
break;
case : //ERROR_INTERNET_OUT_OF_HANDLES
strErrorText = "No more handles could be generated at this time.";
break;
case : //ERROR_INTERNET_POST_IS_NON_SECURE
strErrorText = "The application is posting data to a sever that is not secure.";
break;
case : //ERROR_INTERNET_PROTOCOL_NOT_FOUND
strErrorText = "The requested protocol could not be located.";
break;
case : //ERROR_INTERNET_PROXY_SERVER_UNREACHABLE
strErrorText = "The designated proxy server cannot be reached.";
break;
case : //ERROR_INTERNET_REDIRECT_SCHEME_CHANGE
strErrorText = "The function could not handle the redirection, because the scheme changed (HTTP to FTP).";
break;
case : //ERROR_INTERNET_REGISTRY_VALUE_NOT_FOUND
strErrorText = "A required registry value could not be located.";
break;
case : //ERROR_INTERNET_REQUEST_PENDING
strErrorText = "The required operation could not be completed because one or more requests are pending.";
break;
case : //ERROR_INTERNET_SEC_CERT_CN_INVALID
strErrorText = "SSL certificate common name (host name field) is incorrect. eg if you entered www.server.com and the common name on the certificate says www.different.com.";
break;
case : //ERROR_INTERNET_SEC_CERT_DATE_INVALID
strErrorText = "SSL certificate date that was received from the server is bad. The certificate is expired.";
break;
case : //ERROR_INTERNET_SEC_CERT_REVOKED
strErrorText = "SSL certificate was revoked.";
break;
case : //ERROR_INTERNET_SEC_INVALID_CERT
strErrorText = "SSL certificate is invalid.";
break;
case : //ERROR_INTERNET_SECURITY_CHANNEL_ERROR
strErrorText = "The application experienced an internal error loading the SSL libraries.";
break;
case : //ERROR_INTERNET_SERVER_UNREACHABLE
strErrorText = "The Web site or server indicated is unreachable.";
break;
case : //ERROR_INTERNET_SHUTDOWN
strErrorText = "The Win32 Internet function support is being shut down or unloaded.";
break;
case : //ERROR_INTERNET_TCPIP_NOT_INSTALLED
strErrorText = "The required protocol stack is not loaded and the application cannot start WinSock.";
break;
case : //ERROR_INTERNET_TIMEOUT
strErrorText = "The request has timed out.";
break;
case : //ERROR_INTERNET_UNABLE_TO_CACHE_FILE
strErrorText = "The function was unable to cache the file.";
break;
case : //ERROR_INTERNET_UNABLE_TO_DOWNLOAD_SCRIPT
strErrorText = "The automatic proxy configuration script could not be downloaded. The INTERNET_FLAG_MUST_CACHE_REQUEST flag was set.";
break;
case : //ERROR_INTERNET_UNRECOGNIZED_SCHEME
strErrorText = "The URL scheme could not be recognized, or is not supported.";
break;
default:
strErrorText = "Unknown error code: " + intErrorValue;
break;
}
return (intErrorValue != );
}
} //end of class FtpDll /* try {
TestFtpDll myTest = new TestFtpDll();
FtpDll myFtpDll = new FtpDll(); //instance the FtpDll class to access the FTP functions
myFtpDll.funIOpen();
Console.WriteLine("Connecting...");
myFtpDll.funIConnect(); //use default connection parameters
Console.WriteLine("Change dir to developr...");
myFtpDll.funFTPChangeDir("developr");
Console.WriteLine("Reading first file name in this dir...");
string strFileName = myFtpDll.funFTPFirstFile("*.txt");
Console.WriteLine(strFileName + " found, now uploading...");
myFtpDll.funFTPGetFile(strFileName, strFileName);
// if (new System.IO.FileInfo(strFileName).Exists) {
// Console.WriteLine("Now deleting " + strFileName + " from dir outgoing...");
// myFtpDll.funFTPDeleteFile(strFileName);
// }
// else
// Console.WriteLine("Local copy of the file not found!");
Console.WriteLine("Disconnecting...");
myFtpDll.funFTPDisconnect();
Console.WriteLine("Press N-I key to continue...");
Console.ReadLine(); myFtpDll.funIOpen();
Console.WriteLine("Connecting...");
myFtpDll.funIConnect();
Console.WriteLine("Change dir to developr...");
myFtpDll.funFTPChangeDir("developr");
Console.WriteLine("Now sending test.txt to this dir...");
myFtpDll.funFTPPutFile("test.txt", "test.txt");
Console.WriteLine("Disconnecting...");
myFtpDll.funFTPDisconnect();
Console.WriteLine("Press N-I key to continue...");
Console.ReadLine();
}
catch (Exception e) {
Console.WriteLine("Failed..." + e.Message);
Console.WriteLine("Press N-I key to continue...");
Console.ReadLine();
}
*/
}
csharp: using wininet.dll的更多相关文章
- DLL详解及Denpendcy Walker的使用
下面的文章被N次转载,为了尊重原作,\(^o^)/~,贴出最早发布这篇文章的地址及作者. 动态链接库 Windows的活动大陆 2006-07-26 09:21 作者:狂ρκ来源:电脑爱好者 在 ...
- C#调用C++动态库(dll)
在实际软件开发过程中,由于公司使用了多种语言开发,在C#中可能需要实现某个功能,而该功能可能用其他语言已经实现了,那么我们可以调用其他语言写好的模块吗?还有就是,由于C#开发好的项目,我们可以利用re ...
- [转载]解析WINDOWS中的DLL文件---经典DLL解读
[转载]解析WINDOWS中的DLL文件---经典DLL解读 在Windows世界中,有无数块活动的大陆,它们都有一个共同的名字——动态链接库.现在就走进这些神奇的活动大陆,找出它们隐藏已久的秘密吧! ...
- 全面修复IE,注册IE所有dll
全面修复IE,注册IE所有dll 复制,粘贴到文本文档里,保存成.bat文件,双击运行. rundll32.exe advpack.dll /DelNodeRunDLL32 %systemroot%\ ...
- WinInet API详解
一.概述 WinInet(「Windows Internet」)API帮助程序员使用三个常见的Internet协议,这三个协议是:用于World Wide Web万维网的超文本传输协议(HTTP:Hy ...
- 易语言调用csharp写的COM组件的程序在Win2008上奔溃的解决办法
易语言调用csharp写的COM组件,除了要注册csharp写的dll之外(由于是.net代码,需要用.net自带的注册工具RegAsm.exe注册,具体注册方法为: C:\WINDOWS\Micro ...
- vb6 wininet
Private Const UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; .NET CLR 1.1.4322)&qu ...
- 恶意代码分析学习之dll相关记录
kernel32.dll 这是一个很常见的DLL,它包含核心系统功能,如访问和操作内存.文件和硬件,Kernel32.dl等等 Advapi32.dll 这个DLL提供了对核心Windows组件的访问 ...
- DLL相关下断点
加载DLL 的时候断: sxe ld:[dll] 卸载DLL 的时候断: sxe ud:[dll] 比如: sxe ld:wininet.dll (在wininet.dll 被装载的时候断点) 这里 ...
随机推荐
- 网络基础 08_NAT
1 NAT的基本概念 为什么需要NAT IPv4地址紧缺 什么是NAT NAT(Network Address Translation) 私有IPv4地址 10.0.0.0 - 10.255.255. ...
- windows phpinfo上不能找到memcache扩展 php版本5.6
我的memcache用的我是memcached-win64-1.4.4-14.zip这个版本memcache扩展库下载地址:http://windows.php.net/downloads/pecl/ ...
- 图像的上采样(upsampling)与下采样(subsampled)
缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的有两个:1.使得图像符合显示区域的大小:2.生成对应图像的缩略图. 放大图像(或称为上采样(upsampli ...
- 03-树2 List Leaves (25 分)
Given a tree, you are supposed to list all the leaves in the order of top down, and left to right. I ...
- python的socket.recv函数陷阱
目录 前言 一个粘包实验 执行结果 排错思路 解决和总结 前言 惯例练习历史实验,在编写tcp数据流粘包实验的时候,发现一个奇怪的现象.当远程执行的命令返回结果很短的时候可以正常执行,但返回结果很长时 ...
- (转)Oracle与DB2在数据库高可用技术上的相同与差异探讨
原文:http://www.talkwithtrend.com/Article/178339 数据库建设过程中,高可用是每一个企业数据中心数据库建设过程中至关重要的一个关注点,直接关系到业务连续性和稳 ...
- Java Service Wrapper简介与使用(转)
本文转自https://www.cnblogs.com/zcy_soft/p/3738947.html,写的非常好,珍藏一下 1. wrapper的意思? wrapper在此处理解为“包装”. 2. ...
- Django与前端的交互
在创建Django项目后,我们创建了一个App,我将这个App的名字命名为Cal,并在Cal这个文件夹下创建文件 templates. 创建templates文件夹以后,在项目settings.py文 ...
- C 扩展库 - mysql API
MySQL API C API Data Structures MYSQL This structure represents handler for one database connection. ...
- git hub 建立公钥
1. 执行 $ eval "$(ssh-agent -s)" 2. 增加 ssh $ ssh-add ~/.ssh/id_rsa 3. 复制 生成的key (执行下面命令后就相当 ...