473,545 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managed Code FTP Component Reqd

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
Nov 18 '05 #1
6 1357
You can use the wininet functions, it is quite easy:

using System;
using System.Runtime. InteropServices ;

public class DllImports
{
[DllImport("WinI net.dll", CharSet=CharSet .Auto)]
public static extern IntPtr InternetOpen(
string lpszAgent,
int dwAccessType,
string lpszProxyName,
string lpszProxyBypass ,
int dwFlags);

[DllImport("WinI net.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("WinI net.dll")]
public static extern int InternetCloseHa ndle(IntPtr hInternet);

[DllImport("WinI net.dll", CharSet=CharSet .Auto)]
public static extern int InternetGetLast ResponseInfo(
ref int lpdwError,
System.Text.Str ingBuilder lpszBuffer,
ref int lpdwBufferLengt h);
}

public class some_aspx : System.Web.UI.P age
{
protected void Page_Load(objec t s, EventArgs e)
{
IntPtr InternetOpen = DllImports.Inte rnetOpen(
@"Mozilla/4.0+(compatible ;+MSIE+6.0;+Win dows+NT+5.2;+.N ET+CLR+1.1.4322 )",
0,//INTERNET_OPEN_T YPE_PRECONFIG
null,
null,
0);
if(InternetOpen == IntPtr.Zero)
{
Response.Write( "InternetOp en failed with errorcode:<br>" +
Marshal.GetLast Win32Error());
return;
}
int a = 724;//Just anything
IntPtr InternetConnect = DllImports.Inte rnetConnect(
InternetOpen,
"your server",
21,//INTERNET_DEFAUL T_FTP_PORT
"your username",
"your password",
1,//INTERNET_SERVIC E_FTP
0x08000000,//INTERNET_FLAG_P ASSIVE
new IntPtr(a));
if(InternetConn ect == IntPtr.Zero)
{
Response.Write( "InternetConnec t failed with errorcode:<br>" +
Marshal.GetLast Win32Error());
int lpdwError = 0, lpdwBufferLengt h = 2048;
System.Text.Str ingBuilder lpszBuffer =
new System.Text.Str ingBuilder(lpdw BufferLength);
DllImports.Inte rnetGetLastResp onseInfo(
ref lpdwError,
lpszBuffer,
ref lpdwBufferLengt h);
Response.Write( "<br><br>Intern etGetLastRespon seInfo:");
Response.Write( "<br>Error: " + lpdwError);
Response.Write( "<br>Messag e: " + lpszBuffer.ToSt ring());
DllImports.Inte rnetCloseHandle (InternetOpen);
return;
}
Response.Write( "Connection succeeded.");
DllImports.Inte rnetCloseHandle (InternetOpen);
DllImports.Inte rnetCloseHandle (InternetConnec t);
}
}

Hope this helps
Martin
"Daren Hawes" <da***@webdesig nmagic.com.au> wrote in message
news:uR******** ******@TK2MSFTN GP12.phx.gbl...
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

Nov 18 '05 #2


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!
Nov 18 '05 #3


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
I believe the second (the Page) class is quite simple.

the DllImports in VB.NET should look like:

<DllImport("Win Inet.dll", EntryPoint := "InternetOp en", _
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" <da***@webdesig nmagic.com.au> wrote in message
news:OS******** ******@TK2MSFTN GP11.phx.gbl...


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!

Nov 18 '05 #5


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!
Nov 18 '05 #6
Imports System
Imports System.Runtime. InteropServices

Public Class DllImports
<DllImport("Win Inet.dll", _
EntryPoint:="In ternetOpen", _
CharSet:=CharSe t.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("Win Inet.dll", _
EntryPoint:="In ternetConnect", _
CharSet:=CharSe t.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("Win Inet.dll", _
EntryPoint:="In ternetCloseHand le", _
CharSet:=CharSe t.Auto, ExactSpelling:= True)> _
Public Shared Function InternetCloseHa ndle( _
ByVal hInternet As IntPtr) As Int32
End Function

<DllImport("Win Inet.dll", _
EntryPoint:="In ternetGetLastRe sponseInfo", _
CharSet:=CharSe t.Auto, ExactSpelling:= True)> _
Public Shared Function InternetGetLast ResponseInfo( _
ByRef lpdwError As Int32, _
ByVal lpszBuffer As System.Text.Str ingBuilder, _
ByRef lpdwBufferLengt h 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.Inte rnetOpen( _
"Mozilla/4.0+(compatible ;+MSIE+6.0;+Win dows+NT+5.2;+.N ET+CLR+1.1.4322 )", _
0, _
Nothing, _
Nothing, _
0)
If IntPtr.op_Equal ity(InternetOpe n, IntPtr.Zero) Then
'InternetOpen failed.
'Call Marshal.GetLast Win32Error() for the errorcode
Return False
End If
InternetConnect = DllImports.Inte rnetConnect( _
InternetOpen, _
FtpServerName, _
21, _
FtpUsername, _
FtpPassword, _
1, _
&H8000000, _
p)
If IntPtr.op_Equal ity(InternetCon nect, IntPtr.Zero) Then
'InternetOpen failed.
'Call Marshal.GetLast Win32Error() for the errorcode
'Call InternetGetLast ResponseInfo to see the response
Dim lpdwError As Int32 = 0
Dim lpdwBufferLengt h As Int32 = 2048
Dim lpszBuffer As _
New System.Text.Str ingBuilder(lpdw BufferLength)
DllImports.Inte rnetGetLastResp onseInfo( _
lpdwError, lpszBuffer, lpdwBufferLengt h)
'Free the handle:
DllImports.Inte rnetCloseHandle (InternetOpen)
Return False
End If
' Everything OK
'Free the handles:
DllImports.Inte rnetCloseHandle (InternetOpen)
DllImports.Inte rnetCloseHandle (InternetConnec t)
Return True
End Function
End Class

"Daren Hawes" <da***@webdesig nmagic.com.au> wrote in message
news:#G******** ******@TK2MSFTN GP10.phx.gbl...


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!

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3685
by: JoeZ | last post by:
Hi, Can some one point some samples of calling managed code from unmanaged code. Here is basically what I need: I have an MFC application with several MFC dlls, and I have a new .net component, I need to find a way to call the .net component from either the application or from one of exist MFC dlls.
4
2506
by: 0to60 | last post by:
I'm trying to create a .dll with VS.NET 2003 Architect that contains a math computational component. I need the guts of the thing to be in native code, as performance is key for that part. But, I need a .net wrapper because this "calculator" is actually a component used by an enterprise app written entirely in .net. What I want to do is...
3
1980
by: Robert Hooker | last post by:
Does anyone have any information on when MDX2.0 will come out of Beta? It seems like its been in Beta for a looong time... Rob
0
938
by: shama | last post by:
Hi, When we create shared add-in in visual studio .net 2005 with VC++/ATL as a language, then it creates managed com component or unmanaged com component? In MSDN they had said that "creating managed com component!" using shared add-in!! But when we create share add-in in VC++/ATL it looks unmanaged code! and also does not have CLR support...
7
5130
by: Don | last post by:
Getting errors after following the MSDN article on using VB.NET (and VS2005) for "Implementing a Managed OnSave Event Sink" for Exchange Server 2007. Not sure, but part of the problem may be that it's the 64-bit version of Exchange 2007 installed on Windows Server 2003 Enterprise x64, while the Exchange 2007 SDK samples seem mostly geared...
3
2200
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm trying to specify the requirement from unmanaged DLL component that will be used by a managed application written in C#. The unmanaged DLL is implementing some kind of algorithm for defect detection that will generate results. Each defect result should be a structure containing the data of the found defect. The number of defect is known...
5
7243
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I have a class that is writen in unmanaged pure native C++. This class files (h and cpp) are inserted to a managed C++ (VC++ 2005, C++/CLI) DLL compoenet. This DLL compoenet is used in a C# application. My question is: Does the performance of the unmanaged pure native C++ class described above is the same if it was a in a pure unmanaged...
3
1733
by: iyengar.sheshadri | last post by:
Hi All, Currently we have COM component(dll) implemented using ATL. Because of the current business requirements, we would like to rewrite the COM component in Managed C++ and the clients will be unmanaged C++ and C# . I have been searching net to find some sample code and but could not get it.
66
3285
by: John | last post by:
Hi What are the advantages actually achieved of managed code? I am not talking of theory but in reality. Thanks Regards
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7446
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6003
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.