예제 #1
0
 /// <summary>
 /// Invokes <c>FtpPutFile</c>, handling error conditions.
 /// </summary>
 /// <param name="connect">The connected internet handle.</param>
 /// <param name="localFile">The local file to upload.</param>
 /// <param name="remoteFile">The remote path and filename to which to save the file.</param>
 /// <param name="flags">Additional flags for this action. At least <see cref="FtpHandle.PutFileFlags.Ascii"/> or <see cref="FtpHandle.PutFileFlags.Binary"/> should be specified.</param>
 public static void FtpPutFile(SafeInternetHandle connect, string localFile, string remoteFile, FtpHandle.PutFileFlags flags)
 {
     if (!DoFtpPutFile(connect, localFile, remoteFile, flags, (IntPtr)1))
     {
         throw GetLastInternetException();
     }
 }
예제 #2
0
 /// <summary>
 /// Invokes <c>FtpRenameFile</c>, handling error conditions.
 /// </summary>
 /// <param name="connect">The connected internet handle.</param>
 /// <param name="oldName">The old file name.</param>
 /// <param name="newName">The new file name.</param>
 public static void FtpRenameFile(SafeInternetHandle connect, string oldName, string newName)
 {
     if (!DoFtpRenameFile(connect, oldName, newName))
     {
         throw GetLastInternetException();
     }
 }
예제 #3
0
 /// <summary>
 /// Invokes <c>FtpGetFile</c>, handling error conditions.
 /// </summary>
 /// <param name="connect">The connected internet handle.</param>
 /// <param name="remoteFile">The remote file to download.</param>
 /// <param name="localFile">The local path and filename to which to save the file.</param>
 /// <param name="failIfExists">Whether to fail if the local file specified by <paramref name="localFile"/> already exists.</param>
 /// <param name="flags">Additional flags for this action. At least <see cref="FtpHandle.GetFileFlags.Ascii"/> or <see cref="FtpHandle.GetFileFlags.Binary"/> should be specified.</param>
 public static void FtpGetFile(SafeInternetHandle connect, string remoteFile, string localFile, bool failIfExists, FtpHandle.GetFileFlags flags)
 {
     if (!DoFtpGetFile(connect, remoteFile, localFile, failIfExists, 0, flags, (IntPtr)1))
     {
         throw GetLastInternetException();
     }
 }
예제 #4
0
 /// <summary>
 /// Invokes <c>FtpDeleteFile</c>, handling error conditions.
 /// </summary>
 /// <param name="connect">The connected internet handle.</param>
 /// <param name="fileName">The file to delete.</param>
 public static void FtpDeleteFile(SafeInternetHandle connect, string fileName)
 {
     if (!DoFtpDeleteFile(connect, fileName))
     {
         throw GetLastInternetException();
     }
 }
예제 #5
0
 /// <summary>
 /// Sends a command directly to the FTP server.
 /// </summary>
 /// <param name="connect">The internet connection handle.</param>
 /// <param name="command">The command to send to the FTP server.</param>
 public static void FtpCommand(SafeInternetHandle connect, string command)
 {
     if (!DoFtpCommand(connect, false, 0, command, (IntPtr)1, IntPtr.Zero))
     {
         throw GetLastInternetException();
     }
 }
예제 #6
0
 /// <summary>
 /// Invokes <c>FtpRenameFile</c>, handling error conditions.
 /// </summary>
 /// <param name="connect">The connected internet handle.</param>
 /// <param name="directory">The new current working directory.</param>
 public static void FtpSetCurrentDirectory(SafeInternetHandle connect, string directory)
 {
     if (!DoFtpSetCurrentDirectory(connect, directory))
     {
         throw GetLastInternetException();
     }
 }
예제 #7
0
 /// <summary>
 /// Sets an option on the specified internet handle to the specified <c>int</c> value.
 /// </summary>
 /// <param name="internet">The internet handle.</param>
 /// <param name="option">The option to set.</param>
 /// <param name="value">The value to set the option to.</param>
 public static void SetOption(SafeInternetHandle internet, uint option, int value)
 {
     byte[] data = BitConverter.GetBytes(value);
     if (!DoInternetSetBinaryOption(internet, option, data, 4))
     {
         throw GetLastInternetException();
     }
 }
예제 #8
0
        /// <summary>
        /// Invokes <c>InternetOpen</c>, handling error conditions.
        /// </summary>
        /// <param name="agent">The user agent or process using WinInet. This is sent as the HTTP user agent and WinInet logs.</param>
        /// <param name="accessType">The type of the proxy used, if any.</param>
        /// <param name="proxyName">The name of the proxy server if <paramref name="accessType"/> is <see cref="InternetOpenHandle.AccessType.Proxy"/>.</param>
        /// <param name="proxyBypass">The list of host names or IP addresses that are not routed through the proxy when <paramref name="accessType"/> is <see cref="InternetOpenHandle.AccessType.Proxy"/>. This list may contain wildcards or be equal to the string <c>"&lt;local&gt;"</c>, but should not be an empty string.</param>
        /// <param name="flags">The flags to use for this internet handle.</param>
        /// <returns>The opened internet handle.</returns>
        public static SafeInternetHandle InternetOpen(string agent, InternetOpenHandle.AccessType accessType, string proxyName, string proxyBypass, InternetOpenHandle.Flags flags)
        {
            SafeInternetHandle ret = DoInternetOpen(agent, accessType, proxyName, proxyBypass, flags);

            if (ret.IsInvalid)
            {
                throw GetLastInternetException();
            }

            return(ret);
        }
예제 #9
0
        /// <summary>
        /// Invokes <c>InternetConnect</c>, handling error conditions.
        /// </summary>
        /// <param name="internet">The parent opened internet handle.</param>
        /// <param name="serverName">Name of the server to which to connect.</param>
        /// <param name="serverPort">The server port to which to connect.</param>
        /// <param name="username">The username to use for authentication.</param>
        /// <param name="password">The password to use for authentication.</param>
        /// <param name="service">The service type to which to connect.</param>
        /// <param name="flags">The connection flags.</param>
        /// <returns>The connected internet handle.</returns>
        public static SafeInternetHandle InternetConnect(SafeInternetHandle internet, string serverName, ushort serverPort, string username, string password, InternetConnectHandle.Service service, InternetConnectHandle.Flags flags)
        {
            SafeInternetHandle ret = DoInternetConnect(internet, serverName, serverPort, username, password, service, flags, (IntPtr)1);

            if (ret.IsInvalid)
            {
                throw GetLastInternetException();
            }

            return(ret);
        }
예제 #10
0
        /// <summary>
        /// Invokes <c>FtpGetCurrentDirectory</c>, handling error conditions.
        /// </summary>
        /// <param name="connect">The connected internet handle.</param>
        /// <returns>The current working directory on the remote FTP server.</returns>
        public static string FtpGetCurrentDirectory(SafeInternetHandle connect)
        {
            StringBuilder ret    = new StringBuilder(MAX_PATH);
            uint          length = (uint)ret.Capacity + 1;

            if (!DoFtpGetCurrentDirectory(connect, ret, ref length))
            {
                throw GetLastInternetException();
            }

            return(ret.ToString());
        }
예제 #11
0
        /// <summary>
        /// Invokes <c>InternetSetStatusCallback</c>, handling error conditions. Returns the wrapper for the delegate, which is actually passed to <c>InternetSetStatusCallback</c>.
        /// </summary>
        /// <param name="internet">The internet handle.</param>
        /// <param name="callback">The internet status callback delegate, used to report progress.</param>
        /// <returns>The wrapper created for <paramref name="callback"/>, which is actually passed to the unmanaged <c>InternetSetStatusCallback</c> function.</returns>
        public static object InternetSetStatusCallback(SafeInternetHandle internet, InternetHandle.InternetCallback callback)
        {
            // Note: this will only work for synchronous callbacks! Asynchronous callbacks are not yet supported.
            InternetStatusCallback ret = CreateInternetStatusCallback(callback);

            if (DoInternetSetStatusCallback(internet, ret) == INTERNET_INVALID_STATUS_CALLBACK)
            {
                throw GetLastInternetException();
            }

            return(ret);
        }
예제 #12
0
        /// <summary>
        /// Invokes <c>FtpFindFirstFile</c>, handling error conditions. Returns <c>false</c> if there are no more matching files.
        /// </summary>
        /// <param name="find">The find handle.</param>
        /// <param name="next">On return, the details for the first matching remote file/directory.</param>
        /// <returns><c>true</c> if another file was found; <c>false</c> if there are no more matching files.</returns>
        public static bool FtpFindNextFile(SafeInternetHandle find, out FtpDirectoryEntry next)
        {
            next = new FtpDirectoryEntry();
            FtpWin32FindData data;

            if (!DoFtpFindNextFile(find, out data))
            {
                if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_FILES)
                {
                    return(false);
                }

                throw GetLastInternetException();
            }

            next = data.ToFtpDirectoryEntry();
            return(true);
        }
예제 #13
0
        /// <summary>
        /// Invokes <c>FtpFindFirstFile</c>, handling error conditions. Returns <c>false</c> if there are no matching files.
        /// </summary>
        /// <param name="connect">The internet connection handle.</param>
        /// <param name="search">The search string, which may include wildcards and/or directory information.</param>
        /// <param name="flags">Additional flags for this action.</param>
        /// <param name="first">On return, the details for the first matching remote file/directory.</param>
        /// <param name="find">On return, the find handle.</param>
        /// <returns><c>true</c> if there is at least one matching file; <c>false</c> otherwise.</returns>
        public static bool FtpFindFirstFile(SafeInternetHandle connect, string search, FtpHandle.FindFilesFlags flags, out FtpDirectoryEntry first, out SafeInternetHandle find)
        {
            FtpWin32FindData data;

            find = DoFtpFindFirstFile(connect, search, out data, flags, (IntPtr)1);
            if (find.IsInvalid)
            {
                if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_FILES)
                {
                    first = new FtpDirectoryEntry();
                    return(false);
                }

                throw GetLastInternetException();
            }

            first = data.ToFtpDirectoryEntry();
            return(true);
        }
예제 #14
0
 private static extern bool DoFtpFindNextFile(SafeInternetHandle hFind, out FtpWin32FindData lpvFindData);
예제 #15
0
 private static extern SafeInternetHandle DoFtpFindFirstFile(SafeInternetHandle hConnect, string lpszSearchFile, out FtpWin32FindData lpFindFileData, FtpHandle.FindFilesFlags dwFlags, IntPtr dwContext);
예제 #16
0
 private static extern bool DoFtpSetCurrentDirectory(SafeInternetHandle hConnect, string lpszDirectory);
예제 #17
0
 private static extern bool DoFtpRenameFile(SafeInternetHandle hConnect, string lpszExisting, string lpszNew);
예제 #18
0
 private static extern bool DoFtpRemoveDirectory(SafeInternetHandle hConnect, string lpszDirectory);
예제 #19
0
 private static extern bool DoFtpPutFile(SafeInternetHandle hConnect, string lpszLocalFile, string lpszNewRemoteFile, FtpHandle.PutFileFlags dwFlags, IntPtr dwContext);
예제 #20
0
 private static extern bool DoFtpDeleteFile(SafeInternetHandle hConnect, string lpszFileName);
예제 #21
0
 private static extern bool DoFtpGetCurrentDirectory(SafeInternetHandle hConnect, StringBuilder lpszCurrentDirectory, ref uint lpdwCurrentDirectory);
예제 #22
0
 private static extern bool DoInternetSetBinaryOption(SafeInternetHandle hInternet, uint dwOption, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] byte[] lpBuffer, uint dwBufferLength);
예제 #23
0
 private static extern IntPtr DoInternetSetStatusCallback(SafeInternetHandle hInternet, InternetStatusCallback lpfnInternetCallback);
예제 #24
0
 private static extern bool DoFtpCommand(SafeInternetHandle hConnect, [MarshalAs(UnmanagedType.Bool)] bool fExpectResponse, uint dwFlags, string lpszCommand, IntPtr dwContext, IntPtr phFtpCommand);
예제 #25
0
 private static extern bool DoFtpGetFile(SafeInternetHandle hConnect, string lpszRemoteFile, string lpszNewFile, [MarshalAs(UnmanagedType.Bool)] bool fFailIfExists, uint dwFlagsAndAttributes, FtpHandle.GetFileFlags dwFlags, IntPtr dwContext);
예제 #26
0
 private static extern SafeInternetHandle DoInternetConnect(SafeInternetHandle hInternet, string lpszServerName, ushort nServerPort, string lpszUserName, string lpszPassword, InternetConnectHandle.Service dwService, InternetConnectHandle.Flags dwFlags, IntPtr dwContext);
예제 #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InternetHandle"/> class with the specified safe internet handle.
 /// </summary>
 /// <param name="safeInternetHandle">The safe internet handle.</param>
 protected InternetHandle(SafeInternetHandle safeInternetHandle)
 {
     this.safeInternetHandle = safeInternetHandle;
 }