/// <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();
}
*/
}

最新文章

  1. css常用属性汇总
  2. SpringMVC配置拦截器实现登录控制
  3. for循环中i--的妙用 及 两变量互换数值的问题
  4. 我所理解的ECMAScript、DOM、BOM---写给新手们
  5. 关于轻松安装LNMP和LAMP的编译环境
  6. bootstrap-4
  7. UITableView &#160;折叠效果
  8. check the manual that corresponds to your MySQL server version for the right syntax的错误解析
  9. Axis2 转让Webservice 介面
  10. Spring+SpringMVC+MyBatis+easyUI整合基础篇(十)SVN搭建
  11. 结对作业--基于GUI的四则运算生成器
  12. 【转载】解决nginx负载均衡的session共享问题
  13. ajax提交数据
  14. 腾讯笔试编程题,贪吃的小Q(二分查找)
  15. Lock和synchronized的区别和使用
  16. 第二节:Linux下检出项目和提交项目
  17. mysql_test
  18. NTKO OFFICE文档控件
  19. Python之线程与进程
  20. JQuery Mobile - 导航栏选中状态代码

热门文章

  1. JavaBean简介及使用
  2. 浅谈Android选项卡(三)
  3. QuantLib 金融计算——随机过程之一般 Black Scholes 过程
  4. Fleury算法
  5. 关于莫比乌斯函数的塞 : 莫比乌斯前n项和 , 莫比乌斯函数绝对值的前n项和
  6. mongoengine在python中的使用
  7. hibernate_Session接口_load_get
  8. Scanner类中的nextToken()方法解读
  9. 在WPF中如何使用RelativeSource绑定
  10. ListView和Adapter