ftp again

  • Thread starter Daniel Sélen Secches
  • Start date
D

Daniel Sélen Secches

I've tried to download a file from a ftp server using it... but it doesn't
work....

does anyone has already used it?

Thank's.....



Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet
As Integer) As Integer

Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal
sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer)
As Integer

Private Declare Function InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As
String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal
sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer,
ByVal lContext As Integer) As Integer

Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA"
(ByVal hFtpSession As Integer, ByVal lpszRemoteFile As String, ByVal
lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal
dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer, ByVal dwContext
As Integer) As Boolean

Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA"
(ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, ByVal
lpszRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As
Integer) As Boolean

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim INet, INetConn As Integer

Dim RC As Boolean

INet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)

INetConn = InternetConnect(INet, "ftp.mysite.com", 21, "username",
"password", 1, 0, 0)

RC = FtpGetFile(INetConn, "/web/fim.asp", "c:\fimdaniel.asp", True, 1, 1, 0)

If RC Then MessageBox.Show("Transfer succesfull!")

If Not RC Then MsgBox("Error")

InternetCloseHandle(INetConn)

InternetCloseHandle(INet)
 
C

Crirus

imports SystemNet
.......
' Initialize the WebRequest.
Dim myRequest As WebRequest = WebRequest.Create("ftp://www.mysite.com")

' Return the response.
Dim myResponse As WebResponse = myRequest.GetResponse()

' Code to use the WebResponse goes here.
' Close the response to free resources.
myResponse.Close()
 
S

steve

there's a post entitled "ftp", oddly enough, that suggests how to use the
FtpWebRequest class...i recommend this interface over the suggestion of the
regular HttpWebRequest class.

hth,

steve


| can you give me a example?
|
| thanks...
|
| --
| _____________________________________________
| Este é um grande mail de comunicação
| Daniel Sélen Secches
| ICQ 961630
|
|
| "Crirus" <[email protected]> escreveu na mensagem
| | > Use NET component WebRequest instead
| >
| > Crirus
| >
| >
| > | > > I've tried to download a file from a ftp server using it... but it
| doesn't
| > > work....
| > >
| > > does anyone has already used it?
| > >
| > > Thank's.....
| > >
| > >
| > >
| > > Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal
| > HINet
| > > As Integer) As Integer
| > >
| > > Private Declare Function InternetOpen Lib "wininet.dll" Alias
| > > "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer,
| > ByVal
| > > sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As
| > Integer)
| > > As Integer
| > >
| > > Private Declare Function InternetConnect Lib "wininet.dll" Alias
| > > "InternetConnectA" (ByVal hInternetSession As Integer, ByVal
sServerName
| > As
| > > String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal
| > > sPassword As String, ByVal lService As Integer, ByVal lFlags As
Integer,
| > > ByVal lContext As Integer) As Integer
| > >
| > > Private Declare Function FtpGetFile Lib "wininet.dll" Alias
| "FtpGetFileA"
| > > (ByVal hFtpSession As Integer, ByVal lpszRemoteFile As String, ByVal
| > > lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal
| > > dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer, ByVal
| dwContext
| > > As Integer) As Boolean
| > >
| > > Private Declare Function FtpPutFile Lib "wininet.dll" Alias
| "FtpPutFileA"
| > > (ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, ByVal
| > > lpszRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As
| > > Integer) As Boolean
| > >
| > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > > System.EventArgs) Handles Button1.Click
| > >
| > > Dim INet, INetConn As Integer
| > >
| > > Dim RC As Boolean
| > >
| > > INet = InternetOpen("MyFTP Control", 1, vbNullString, vbNullString, 0)
| > >
| > > INetConn = InternetConnect(INet, "ftp.mysite.com", 21, "username",
| > > "password", 1, 0, 0)
| > >
| > > RC = FtpGetFile(INetConn, "/web/fim.asp", "c:\fimdaniel.asp", True, 1,
| 1,
| > 0)
| > >
| > > If RC Then MessageBox.Show("Transfer succesfull!")
| > >
| > > If Not RC Then MsgBox("Error")
| > >
| > > InternetCloseHandle(INetConn)
| > >
| > > InternetCloseHandle(INet)
| > >
| > >
| > > --
| > > _____________________________________________
| > > Este é um grande mail de comunicação
| > > Daniel Sélen Secches
| > > ICQ 961630
| > >
| > >
| >
| >
|
|
 
T

Tom Shelton

I've tried to download a file from a ftp server using it... but it doesn't
work....

does anyone has already used it?

Thank's.....

<snip>

This works for me...

Option Strict On
Option Explicit On

Imports System.Runtime.InteropServices

Module Module1
Private Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInternet As IntPtr) As Boolean

Private Declare Auto Function InternetOpen Lib "wininet.dll" _
(ByVal lpszAgent As String, _
ByVal lAccessType As Integer, _
ByVal lpszProxyName As String, _
ByVal lpszProxyBypass As String, _
ByVal dwFlags As Integer) As IntPtr

Private Declare Auto Function InternetConnect Lib "wininet.dll" _
(ByVal hInternet As IntPtr, _
ByVal lpszServerName As String, _
ByVal nServerPort As Short, _
ByVal lpszUserName As String, _
ByVal lpszPassword As String, _
ByVal dwService As Integer, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As IntPtr

Private Declare Auto Function FtpGetFile Lib "wininet.dll" _
(ByVal hConnect As IntPtr, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Integer, _
ByVal dwFlags As Integer, _
ByVal dwConext As Integer) As Boolean

Private Declare Auto Function FtpPutFile Lib "wininet.dll" _
(ByVal hConnect As IntPtr, _
ByVal lpszLocalFile As String, _
ByVal lpszNewRemoteFile As String, _
ByVal dwFlags As Integer, _
ByVal dwContext As Integer) As Boolean

Sub Main()
Dim hInet As IntPtr
Dim hConn As IntPtr

hInet = InternetOpen("my ftp", 1, vbNullString, vbNullString, 0)
Console.WriteLine("hInet = {0}", hInet)

hConn = InternetConnect(hInet, "yourserver", 21, "yourusername",
"yourpassword", 1, 0, 0)
Console.WriteLine("hConn = {0}", hConn)

Console.WriteLine("FtpGetFile Result = {0}", FtpGetFile(hConn,
"wininet.txt", "wininet.txt", True, 1, 1, 0))

InternetCloseHandle(hConn)
InternetCloseHandle(hInet)
End Sub

End Module


HTH
 
H

Herfried K. Wagner [MVP]

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top