ftp upload for pocket pc

G

Guest

Hi please can someone help me, i'm so desperate.

I'm trying to write a small app in vb.net cf that basically uploads a file
to a server from a pocket pc 2003

I've been using wininet without any success. the ftpputfile just won't work!
the code is below if its a simple case of my stupidity! Internetconnect and
internetopen return values without problem but ftpputfile is always false.
I've downloaded IPworks and used their excellent library and it works
brilliantly but i cann't use external libs or any 3rd party stuff in this
app. ANyone got any suggestions how it might be possible to write a simple
library thing? all i need is connect and upload! I've seen a few that look
easy but they're in C# and my C# is uselss!

Thanks so much i really appreciate any time you can give.



Declare Function InternetConnect Lib "wininet" Alias "InternetConnectW"
(ByVal hInet As Integer, ByVal lpszServerName As String, ByVal nServerPort As
Integer, ByVal lpszUserName As String, ByVal lpszPassword As String, ByVal
dwService As Integer, ByVal dwFlags As Integer, ByVal dwContext As Integer)
As Integer

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

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


Public Const INTERNET_SERVICE_FTP As Integer = 1
Public Const INTERNET_OPEN_TYPE_PRECONFIG As Integer = 0
Public Const INTERNET_FLAG_PASSIVE As Integer = 0

Dim INet As Integer
Dim INetConn As Integer
Dim RC As Boolean
On Error Resume Next

INet = InternetOpen(("testftp2"), INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)

INetConn = InternetConnect(INet, "myserver", 21, "username", "password",
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)

RC = FtpPutFile(INetConn, "/My Documents/Hello.txt", "file1.txt", 4, 4)
If RC = True Then
MsgBox("Transfer succesfull!")
Else
MsgBox("transfer failed " & Err.Description)
End If
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
 
P

Peter Foot [MVP]

Your local path may not be valid,aslo you should pass 0 in the dwContext
argument, try:-
RC = FtpPutFile(INetConn, "\My Documents\Hello.txt", "file1.txt", 4, 0)

Peter
 
C

Christian Schwarz

I've been using wininet without any success. the ftpputfile just won't

Maybe you could try FtpOpenFile() and InternetWriteFile() functions. They
work fine for me ...

[DllImport("wininet.dll", EntryPoint = "FtpOpenFile", SetLastError = true)]
private extern static IntPtr FtpOpenFile(IntPtr hFtp, string fileName,
UInt32 dwAccess, UInt32 dwFlags, IntPtr dwContext);

[DllImport("wininet.dll", EntryPoint = "InternetWriteFile", SetLastError =
true)]
private extern static bool InternetWriteFile(IntPtr hFile, byte[]
sendBuffer, Int32 dwNumberOfBytesToWrite, ref Int32
lpdwNumberOfBytesWritten);

Greetings, Christian
 
G

Guest

Hi really really appreciate you guys helping but no none of that works still!
ftpputfile still returns false.
 
G

Guest

hi thanks so much for helping. I've been trying and cann't get ftpopenfile to
work either.
(i'm using visual basic btw)

Declare Function ftpopenfile Lib "wininet.dll" (ByVal hFtp As Int32, ByVal
fileName As String, ByVal dwAccess As Int32, ByVal dwFlags As Int32, ByVal
dwContext As Int32) As Int32

dim inetopp as int32

inetopp = ftpopenfile(INetConn, "file1.txt", 2, 2, 0)

what parameters are best to use, these don't seem to work for me! inetopp
still returns 0. i tried int32 but it works no better than integer.

THanks again for helping.

Christian Schwarz said:
I've been using wininet without any success. the ftpputfile just won't
work!

Maybe you could try FtpOpenFile() and InternetWriteFile() functions. They
work fine for me ...

[DllImport("wininet.dll", EntryPoint = "FtpOpenFile", SetLastError = true)]
private extern static IntPtr FtpOpenFile(IntPtr hFtp, string fileName,
UInt32 dwAccess, UInt32 dwFlags, IntPtr dwContext);

[DllImport("wininet.dll", EntryPoint = "InternetWriteFile", SetLastError =
true)]
private extern static bool InternetWriteFile(IntPtr hFile, byte[]
sendBuffer, Int32 dwNumberOfBytesToWrite, ref Int32
lpdwNumberOfBytesWritten);

Greetings, Christian
 
C

Chris Tacke, eMVP

1. Try with an anonymous connection
2. Let us know what GetLastWin32Error returns after the failed P/Invoke call

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
G

Guest

Hi chris thanks so much for helping

This thing is so weird. OK if i try and connect to my company ftp server
(which obviously has a username and password) then internetconnect = 0.
If i try and connect to my localhost (which allows anonymous connections)
internetconnect gets a value but RC still = false.
I'm using 2002 emulator.
The real device is 2003 and i can never get it to hold a value for
internetconnect whatever i do!!!!!

i'm not veyr good with error handling, and don't fully know how to use
getlasterror here's what i've tried on the device instead:
the message box replies "transfer failed 12029"
no err.description

dim hello as integer
dim goodbye as string
INetConn = InternetConnect(INet, "ftp.tvl.ca", 21, "upload", "tvl",
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)

hello = Err.LastDllError
goodbye = Err.Description

RC = FtpPutFile(INetConn, "\My Documents\Hello.txt", "file1.txt", 3,
0)

If RC = True Then
MsgBox("Transfer succesfull!")
Else
MsgBox("transfer failed " & hello & goodbye)
End If
 
P

Paul G. Tobey [eMVP]

I doubt that you've been abandoned, but what have you done to try to make
progress. Sitting around waiting for someone to fix your problem is
unlikely to be the best use of your time.

// MessageId: ERROR_INTERNET_CANNOT_CONNECT
//
// MessageText:
//
// A connection with the server could not be established
//
#define ERROR_INTERNET_CANNOT_CONNECT 12029L

Pulled it right out of the C header files...

Paul T.
 
G

Guest

sorry sorry sorry please don't think me as rude or impatient, desperate yes
but not trying to be un-gratefull!

I've brought a book, pocket pc network programming which doesn't seem to
offer anything different. I've ran a loop that tests progressive combinations
of integers for all the values in the internetconnect and ftpopenfile. I've
studied the msdn files on internetopen and internetconnect.

i got internetconnect working on the 2003 device but only with
internet_service_ftp = 3 which i think means http which then returns an
incompatable error with ftpputfile! I'm even trying to use a C# library i
found converted to a dll and run in my vb.net prog. but i don't know c# which
makes it really hard! I could ramble on for ages with what i've tried, none
of its got me anywhere!

Sorry guys but thanks so much for your help, its really appreciated.
 
P

Paul G. Tobey [eMVP]

You saw Sergey's post about only anonymous access being permitted on some
PPC devices?

Paul T.
 
G

Guest

yea but i'm using ppc2003 and if i use the demo version of IP*Works library
it works like a dream!
 
P

Paul G. Tobey [eMVP]

All I can tell you, then, is the post the complete code for the smallest
possible sample, along with the information about the server you are using,
how it is configured, and, if possible, the information for accessing it
from our own devices...

Paul T.
 
G

Guest

hey guys, look i got internetconnection working :D but ftpputfile is
behaving weirdly.

it uploads the file but the file is empty, i've tried everything my tiny
brain can cope with and it will not upload the file from my ppc2003 to the
ftp site? The error is 12003.

I've also tried microswofts workaround using the ftoopenfile property but i
cann't get that working either. (code will follow if desired)

Any one got any ideas, i'm aware this has been asked before but i cann't
find a working solution anywhere. I'd be so appreciative if i can get this
fixed:

Private Const INTERNET_FLAG_TRANSFER_BINARY As Integer = &H2
Private Const INTERNET_FLAG_TRANSFER_ASCII = &H1
Private Const INTERNET_SERVICE_FTP As Integer = 1
Private Const INTERNET_OPEN_TYPE_DIRECT As Integer = 1
Private Const INTERNET_FLAG_PASSIVE As Integer = &H8000000

INet = InternetOpen("test", 3, vbNullString, vbNullString, 0)

INetConn = InternetConnect(INet, host, 21, username, password,
INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)

res = FtpPutFile(INetConn, "/My Documents/Hello.txt", "file1.txt",
INTERNET_FLAG_TRANSFER_BINARY, 0)

Dim hello As Integer = Err.LastDllError
If res = False Then
MsgBox("oh pants" & hello)
End If
 
P

Paul G. Tobey [eMVP]

Well, if you search for 12003 in the header files for the C SDK, you'll find
12003 (you sometimes want to search for the hex version, too, but not in
this case, I think), in two places:

//
// MessageId: ERROR_INTERNET_EXTENDED_ERROR
//
// MessageText:
//
// The server returned extended information
//
#define ERROR_INTERNET_EXTENDED_ERROR 12003L

and

//
// MessageId: ERROR_SXS_ASSEMBLY_NOT_FOUND
//
// MessageText:
//
// The referenced assembly is not installed on your system.
//
#define ERROR_SXS_ASSEMBLY_NOT_FOUND 12003L

I'll assume for now that it's the first, not the second, that is the
problem. Looking up this error in the help, you find that the description
says the following:

An extended error was returned from the server. This is typically a string
or buffer containing a verbose error message. Call
InternetGetLastResponseInfo to retrieve the error text.

You should do this.

Paul T.
 
G

Guest

Hi me again, i'm still stuck and even more desperate! here's the error:

"An unhandled exception of type 'System.Exception' occurred in TestFTP.exe
Additional information: Error:12003"

i tried this:
http://support.microsoft.com/kb/168492/EN-US/

our sever doesn't like passive ftp anyway. InetOpen and Connect get values
but res fails every time! I've changed the paramaters to this but still
nothing:

I'm thinking it must be some kind of error on the data transfer level? Is
there a setting on my ppc2003 device i need to check? I've had a few classes
fail as soon as they try and run the data transfer!

INet = InternetOpen("test", 3, vbNullString, vbNullString,
INTERNET_FLAG_ASYNC)

INetConn = InternetConnect(INet, host, 21, username, password,
INTERNET_SERVICE_FTP, INTERNET_FLAG_ASYNC, 0)

res = FtpPutFile(INetConn, fileName, "file1.txt",
INTERNET_FLAG_TRANSFER_BINARY, 0)


Private Const INTERNET_FLAG_TRANSFER_BINARY As Integer = &H2
Private Const INTERNET_SERVICE_FTP As Integer = 1
Private Const INTERNET_OPEN_TYPE_DIRECT As Integer = 1
Private Const INTERNET_FLAG_PASSIVE As Integer = &H8000000
Private Const INTERNET_FLAG_ASYNC As Integer = &H10000000

Thanks paul, everyone, anyone for any help.
 
C

Chris Tacke, eMVP

Personally I'd abandon the Wininet stuff - it's too unreliable. Go with a
pure socket implementation. To make your life easy just use the one I
already wrote and put into the SDF source vault. It's not in any release
yet as I expect the interface to change to match the FF 2.0 interface, so
you'll have to get the code and compile it yourself.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
G

Guest

OK fair enough, i think your probabbly right, wininet is useless.

I started writing a socket solution but it's quiet over my head, you know
any good sites that can help me with this? the more basic the better!

You mentioned using the one you've already written, how do i get hold of that?

Thanks anyway guys, you've been a big help.
 

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

Similar Threads


Top