Here's my code:
Imports System.Net.sockets
Imports System.Net
...
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21 ' default for FTP
servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000 ' used for FTP
connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0 ' use registry
configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1 ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3 ' via named
proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 ' prevent
using java/script/INS
Const MAX_PATH = 260
Private Structure FILETIME
Dim dwLowDateTime As Long
Dim dwHighDateTime As Long
End Structure
Private Structure WIN32_FIND_DATA
Dim dwFileAttributes As Long
Dim ftCreationTime As FILETIME
Dim ftLastAccessTime As FILETIME
Dim ftLastWriteTime As FILETIME
Dim nFileSizeHigh As Long
Dim nFileSizeLow As Long
Dim dwReserved0 As Long
Dim dwReserved1 As Long
Dim cFileName As String
Dim cAlternate As String
End Structure
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByRef
hInet As Long) As Long
Public Declare Function InternetConnect Lib "wininet.dll" Alias
"InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As
String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal
sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal
lContext As Long) As Long
Private Declare Function InternetOpen Lib "wininet.dll" Alias
"InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal
sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As
Long
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As
String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias
"FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal
lpszCurrentDirectory As String, ByVal lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias
"FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As
String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias
"FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As
String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias
"FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As
Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias
"FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String,
ByVal lpszNew As String) As Boolean
Private Declare Function FtpGetFile Lib "wininet.dll" Alias
"FtpGetFileA" (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal
lpszNewFile As String, ByVal fFailIfExists As Long, ByVal
dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long)
As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias
"FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal
lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long)
As Boolean
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll"
Alias "InternetGetLastResponseInfoA" (ByVal lpdwError As Long, ByVal
lpszBuffer As String, ByVal lpdwBufferLength As Long) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias
"FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As
String, ByVal lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal
dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias
"InternetFindNextFileA" (ByVal hFind As Long, ByVal lpvFindData As
WIN32_FIND_DATA) As Long
Const PassiveConnection As Boolean = True
...
Dim i As Long = 1
Dim iCount As Long
Dim iK As Boolean
Dim scUserAgent As String = "VB OpenUrl"
i = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT,
vbNullString, vbNullString, 0)
iCount = InternetConnect(i,
"ftp.jpccontrols.com/Flash_Programming/Flash_Programs/BC_Group/",
INTERNET_DEFAULT_FTP_PORT, "Anonymous", "Guest", INTERNET_SERVICE_FTP, 0, 0)
iK = FtpGetFile(iCount, "ESU-2400.exe", "\Hard
Disk\ESU-2400\ESU-2400_FTP.exe", True, 1, 0, 0)
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:F262D3DE-C367-49C4...@microsoft.com...
As far as the Ascii reference, I had no idea that's what it did, thanks for
the input. I just tried InternetOpenW and it didn't work either...
I found the reference code in a sample somewhere, figured if it worked for
them it would work for me. I've also tried the OpenNETCF, but couldn't find
a straight example of what to do once it was included in the project. There
are lots of C# examples, but not much for VB.
Paul T.
"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:F262D3DE-C367-49C4...@microsoft.com...
I wrote it right off the RFC using plain sockets. The object model is
really simple and should be self explanatory in any language. I dislike the
version in the SDF because it's modeleld after the Microsoft stream-based
version which is nothing but confusing in my mind.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:DEA9C27F-CAFE-4E3C...@microsoft.com...
Ah, here it is. You've got a bunch of stuff declared 'Long'. Wrong. C++
'long' == VB.NET 'Int' or, specifically, 'Int32'. Long is a 64-bit integer.
Here's what I got to work:
-----
Dim i As Int32 = 1
Dim iCount As Int32
Dim iK As Boolean
Dim scUserAgent As String = "VB OpenUrl"
i = InternetOpenW(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString,
vbNullString, 0)
iCount = InternetConnectW(i, "<servername>", INTERNET_DEFAULT_FTP_PORT,
"<username>", "<password>", INTERNET_SERVICE_FTP, 0, 0)
iK = FtpGetFileW(iCount, "\test.txt", "\flash\text.txt", True, 1, 0, 0)
InternetCloseHandle(iCount)
InternetCloseHandle(i)
....
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByRef hInet
As Int32) As Int32
Public Declare Function InternetConnectW Lib "wininet.dll" (ByVal
hInternetSession As Int32, ByVal sServerName As String, ByVal nServerPort As
Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal
lService As Int32, ByVal lFlags As Int32, ByVal lContext As Int32) As Int32
Private Declare Function InternetOpenW Lib "wininet.dll" (ByVal sAgent As
String, ByVal lAccessType As Int32, ByVal sProxyName As String, ByVal
sProxyBypass As String, ByVal lFlags As Int32) As Int32
Private Declare Function FtpGetFileW Lib "wininet.dll" (ByVal hConnect As
Int32, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal
fFailIfExists As Int32, ByVal dwFlagsAndAttributes As Int32, ByVal dwFlags
As Int32, ByRef dwContext As Int32) As Boolean
-----
Paul T.
"lsimoni" <lsi...@discussions.microsoft.com> wrote in message
news:DEA9C27F-CAFE-4E3C...@microsoft.com...
I know just enough about vb.net to be dangerous. VB6 was much more
forgiving and easier to get by with.
I'll remember the C++ long translation, as I'm sure this isn't the last API
that I need to call.
"Paul G. Tobey [eMVP]" wrote:
> No, not everything, just everything that jumps out at us. I'm sure there's
> an error there.
>
> Ah, here it is. You've got a bunch of stuff declared 'Long'. Wrong. C++
> 'long' == VB.NET 'Int' or, specifically, 'Int32'. Long is a 64-bit integer.
> Here's what I got to work:
>
> -----
>
> Dim i As Int32 = 1
>
> Dim iCount As Int32
>
> Dim iK As Boolean
>
> Dim scUserAgent As String = "VB OpenUrl"
>
> i = InternetOpenW(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString,
> vbNullString, 0)
>
> iCount = InternetConnectW(i, "<servername>", INTERNET_DEFAULT_FTP_PORT,
> "<username>", "<password>", INTERNET_SERVICE_FTP, 0, 0)
>
> iK = FtpGetFileW(iCount, "\test.txt", "\flash\text.txt", True, 1, 0, 0)
>
> InternetCloseHandle(iCount)
>
> InternetCloseHandle(i)
>
> .....