473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1347
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" <da***@webdesignmagic.com.au> wrote in message
news:uR**************@TK2MSFTNGP12.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("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" <da***@webdesignmagic.com.au> wrote in message
news:OS**************@TK2MSFTNGP11.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("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" <da***@webdesignmagic.com.au> wrote in message
news:#G**************@TK2MSFTNGP10.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
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...
4
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...
3
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
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...
7
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...
3
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...
5
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#...
3
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...
66
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.