![]() |
|
|
|||||||
![]() |
ASP Net - Managed Code FTP Component Reqd |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Posts: n/a
|
Hi,
My web host has a low security setting on the shared .net server I use. I cannot use third party dll's or install assemblies in the GAC. All I need to do is verify that a FTP login is true. I do not need to move files etc, simply check if the ftp details that were collected in a web form actually authenticate with the remote ftp server. Can this be completed using managed code only? Please help |
|
|
|
#2 |
|
Posts: n/a
|
You can use the wininet functions, it is quite easy:
using System; using System.Runtime.InteropServices; public class DllImports { [DllImport("WinInet.dll", CharSet=CharSet.Auto)] public static extern IntPtr InternetOpen( string lpszAgent, int dwAccessType, string lpszProxyName, string lpszProxyBypass, int dwFlags); [DllImport("WinInet.dll", CharSet=CharSet.Auto)] public static extern IntPtr InternetConnect( IntPtr hInternet, string lpszServerName, int nServerPort, string lpszUsername, string lpszPassword, int dwService, int dwFlags, IntPtr dwContext); [DllImport("WinInet.dll")] public static extern int InternetCloseHandle(IntPtr hInternet); [DllImport("WinInet.dll", CharSet=CharSet.Auto)] public static extern int InternetGetLastResponseInfo( ref int lpdwError, System.Text.StringBuilder lpszBuffer, ref int lpdwBufferLength); } public class some_aspx : System.Web.UI.Page { protected void Page_Load(object s, EventArgs e) { IntPtr InternetOpen = DllImports.InternetOpen( @"Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+.NET+CL R+1.1.4322)", 0,//INTERNET_OPEN_TYPE_PRECONFIG null, null, 0); if(InternetOpen == IntPtr.Zero) { Response.Write("InternetOpen failed with errorcode:<br>" + Marshal.GetLastWin32Error()); return; } int a = 724;//Just anything IntPtr InternetConnect = DllImports.InternetConnect( InternetOpen, "your server", 21,//INTERNET_DEFAULT_FTP_PORT "your username", "your password", 1,//INTERNET_SERVICE_FTP 0x08000000,//INTERNET_FLAG_PASSIVE new IntPtr(a)); if(InternetConnect == IntPtr.Zero) { Response.Write("InternetConnect failed with errorcode:<br>" + Marshal.GetLastWin32Error()); int lpdwError = 0, lpdwBufferLength = 2048; System.Text.StringBuilder lpszBuffer = new System.Text.StringBuilder(lpdwBufferLength); DllImports.InternetGetLastResponseInfo( ref lpdwError, lpszBuffer, ref lpdwBufferLength); Response.Write("<br><br>InternetGetLastResponseInf o:"); Response.Write("<br>Error: " + lpdwError); Response.Write("<br>Message: " + lpszBuffer.ToString()); DllImports.InternetCloseHandle(InternetOpen); return; } Response.Write("Connection succeeded."); DllImports.InternetCloseHandle(InternetOpen); DllImports.InternetCloseHandle(InternetConnect); } } Hope this helps Martin "Daren Hawes" <> wrote in message news:... > Hi, > > My web host has a low security setting on the shared .net server I use. I > cannot use third party dll's or install assemblies in the GAC. > > All I need to do is verify that a FTP login is true. I do not need to move > files etc, simply check if the ftp details that were collected in a web form > actually authenticate with the remote ftp server. Can this be completed > using managed code only? > > Please help > > |
|
|
|
#3 |
|
Posts: n/a
|
Is there a VB version around? Thanks Daren *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
|
|
|
#4 |
|
Posts: n/a
|
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
|
|
|
#5 |
|
Posts: n/a
|
I believe the second (the Page) class is quite simple.
the DllImports in VB.NET should look like: <DllImport("WinInet.dll", EntryPoint := "InternetOpen", _ CharSet := CharSet.Auto, ExactSpelling := True)> _ public shared function InternetOpen( _ lpszAgent as string, _ dwAccessType as int32, _ lpszProxyName as string, _ lpszProxyBypass as string, _ dwFlags as int32) as IntPtr End function and so on... Greetings Martin "Daren Hawes" <> wrote in message news:... > > > Is there a VB version around? > > Thanks Daren > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it! |
|
|
|
#6 |
|
Posts: n/a
|
Hi Martin, I am so sorry, but I have tried to convert to VB. I am a student, and find convering some things from C# to VB, especially system DLL imports! Is there anywhere you can point me for a VB version of both the class and the ASP.NET page? Thx Daren In the meantime I will search around... *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
|
|
|
#7 |
|
Posts: n/a
|
Imports System
Imports System.Runtime.InteropServices Public Class DllImports <DllImport("WinInet.dll", _ EntryPoint:="InternetOpen", _ CharSet:=CharSet.Auto, ExactSpelling:=True)> _ Public Shared Function InternetOpen( _ ByVal lpszAgent As String, _ ByVal dwAccessType As Int32, _ ByVal lpszProxyName As String, _ ByVal lpszProxyBypass As String, _ ByVal dwFlags As Int32) As IntPtr End Function <DllImport("WinInet.dll", _ EntryPoint:="InternetConnect", _ CharSet:=CharSet.Auto, ExactSpelling:=True)> _ Public Shared Function InternetConnect( _ ByVal hInternet As IntPtr, _ ByVal lpszServerName As String, _ ByVal nServerPort As Int32, _ ByVal lpszUsername As String, _ ByVal lpszPassword As String, _ ByVal dwService As Int32, _ ByVal dwFlags As Int32, _ ByVal dwContext As IntPtr) As IntPtr End Function <DllImport("WinInet.dll", _ EntryPoint:="InternetCloseHandle", _ CharSet:=CharSet.Auto, ExactSpelling:=True)> _ Public Shared Function InternetCloseHandle( _ ByVal hInternet As IntPtr) As Int32 End Function <DllImport("WinInet.dll", _ EntryPoint:="InternetGetLastResponseInfo", _ CharSet:=CharSet.Auto, ExactSpelling:=True)> _ Public Shared Function InternetGetLastResponseInfo( _ ByRef lpdwError As Int32, _ ByVal lpszBuffer As System.Text.StringBuilder, _ ByRef lpdwBufferLength As Int32) As Int32 End Function Public Shared Function CheckFtpLogin( _ ByVal FtpServerName As String, _ ByVal FtpUsername As String, _ ByVal FtpPassword As String) As Boolean Dim InternetOpen, InternetConnect As IntPtr Dim a As Int32 = 724 'whatever Dim p As New IntPtr(a) InternetOpen = DllImports.InternetOpen( _ "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.2;+.NET+CL R+1.1.4322)", _ 0, _ Nothing, _ Nothing, _ 0) If IntPtr.op_Equality(InternetOpen, IntPtr.Zero) Then 'InternetOpen failed. 'Call Marshal.GetLastWin32Error() for the errorcode Return False End If InternetConnect = DllImports.InternetConnect( _ InternetOpen, _ FtpServerName, _ 21, _ FtpUsername, _ FtpPassword, _ 1, _ &H8000000, _ p) If IntPtr.op_Equality(InternetConnect, IntPtr.Zero) Then 'InternetOpen failed. 'Call Marshal.GetLastWin32Error() for the errorcode 'Call InternetGetLastResponseInfo to see the response Dim lpdwError As Int32 = 0 Dim lpdwBufferLength As Int32 = 2048 Dim lpszBuffer As _ New System.Text.StringBuilder(lpdwBufferLength) DllImports.InternetGetLastResponseInfo( _ lpdwError, lpszBuffer, lpdwBufferLength) 'Free the handle: DllImports.InternetCloseHandle(InternetOpen) Return False End If ' Everything OK 'Free the handles: DllImports.InternetCloseHandle(InternetOpen) DllImports.InternetCloseHandle(InternetConnect) Return True End Function End Class "Daren Hawes" <> wrote in message news:#... > > > Hi Martin, > > I am so sorry, but I have tried to convert to VB. I am a student, and > find convering some things from C# to VB, especially system DLL imports! > > Is there anywhere you can point me for a VB version of both the class > and the ASP.NET page? > > Thx Daren > > In the meantime I will search around... > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it! |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How To Access HTML elements in code behind??? | nedums_b | Software | 1 | 02-07-2008 06:15 PM |
| VHDL code | jyothikiranmai | Software | 0 | 10-04-2007 06:40 AM |
| Circumvent Region Code | hufaunder@yahoo.com | DVD Video | 11 | 01-29-2007 08:51 PM |
| Sony's BR Disc won't downrez to component | Goro | DVD Video | 7 | 03-16-2006 03:44 PM |
| converting composite to component? | Brandi Clark | DVD Video | 7 | 02-22-2004 04:14 PM |