Please help! Can't FTP to server, yet applications and librariescan.

S

Sean Patterson

...at least in my code anyway!

I'm almost at my wits end here. 8^D I've written a simple logging style
tool that when the user docks the item in the cradle and hits the
synchronzie button, it FTPs the file to a remote server.

I have the scan gun cradled and can get out on the internet using
Internet Explorer. I also installed neoFTP and can connect to the FTP
server through that when I run it (note that it is a completely separate
computer than the one the cradle is attached to). I have my IPSec
diabled to make sure nothing is blocking traffic. I've even downloaded
and integrated the basic Rebex FTP class to do the file transfer and
things work fine.

However, when my code tries to connect to the same IP address, I get
problems. I've borrowed some open source code and this is the connect
method used. Note, my method that makes the connection is specifying an
IP address, not an domain name that needs resolving, so hopefully that
eliminates a step

Public Function Login() As Boolean
Dim ep As IPEndPoint
Dim ServerIP As IPAddress

m_objClientSocket = New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
ep = New IPEndPoint(Dns.Resolve(m_sRemoteHost).AddressList(0),
m_iRemotePort)

Try
m_objClientSocket.Connect(ep)
Catch ex As Exception
MessageString = m_sReply
Throw New IOException("Couldn't connect to remote server")
End Try

ReadReply()
If (m_iRetValue <> 220) Then
CloseConnection()
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

SendCommand("USER " & m_sRemoteUser)
If (Not (m_iRetValue = 331 Or m_iRetValue = 230)) Then
Cleanup()
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

If (m_iRetValue <> 230) Then
SendCommand("PASS " & m_sRemotePassword)
If (Not (m_iRetValue = 230 Or m_iRetValue = 202)) Then
Cleanup()
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If
End If

m_bLoggedIn = True
ChangeDirectory(m_sRemotePath)

' Return the end result.
Return m_bLoggedIn
End Function

When it tries to connect, I get the error "This is usually a temporary
error during hostname resolution and means that the local server did not
receive a response for an authoritative server."

I've been virtually everywhere on the net and am having no luck. Please
help!

If you want to swing things the other angle, I downloaded and started a
small FTP class based on the wininet.dll library and the connection
within that just hangs.

What am I missing guys?!

Thanks in advance for any insight you may have!

- Sean
 
E

Ed Kaim

The first thing I'd check for is anything that might prevent the connection
(such as a firewall from SP2, etc).

Other than that, have you tried using the TcpClient class instead of the
base Socket? Although it may not make a difference, I find that using the
higher level networking classes when possible to remove moving parts. There
have been a few times where I've gotten errors that disappear when I move up
the abstraction stack, which is likely due to bugs I've overlooked.
 
P

Paul G. Tobey [eMVP]

Hang on. You said that you were passing an IP address, not something that
had to be resolved, but then, in the code, you're calling DNS.Resolve. What
gives? You also haven't indicated what port you're trying to connect to,
although I'd assume that it is the FTP port, 21.

Also, what server are you trying to connect to?

Just to make sure I understand, you've run this other test code *from the
same device*, *in the same connected state (cradle or whatever)*?

Paul T.
 
S

Sean Patterson

Hey guys! Thanks for the input! I'll see what I can dig up on the TCP
Class for FTP transport.

But to answer the questions:
I'm not sure how much the firewall is the issue I'm on a Win2K box and
I've disabled my IPSec policy when I've run tests. I've also gotten it
to connect using neoFTP and the Rebex libraries with IPSec enabled,
since port 21 is open by default and I have the whole subdomain for the
server opened for full access.

Yes, the original code was using DNS.Resolve, but I did change that at
one point in time to just generate an IPAddress object based on the
string of the IPAddress and generate the EndPoint that way. I got the
same effect. I haven't done much socket programming yet, so I'm looking
at examples on line and trying to start from there.

I am connecting to the standard port 21 and the server I'm connecting to
is a Win2K Server box that has my IP address opened for FTP connections.
Again, just to confirm, I can connect and upload files to this server
using neoFTP installed on the same handheld device, as well as connect
and upload files when I use the Rebex.Net.FTP object that I downloaded
online. I just can't get my own code to work.

Hopefully this will provide some insight! Thanks!
 
P

Paul G. Tobey [eMVP]

OK, fine, but, if you're going to post the cost, you have to post the *real*
code, not the code before you made this or that change to it...

Paul T.
 
S

Sean Patterson

Woo Hoo! It's amazing what a fresh pair of eyes can do to rectify a
situation. I was able to get my scan gun to finally connect, now
migrating in the send and receive methods will be a sinch. Essentially
what I did was create an IPAddress object based off of the IP Address
being specified to eliminate the whole DNS Resolution gig. So here is my
new connect method, with the old info commented out, just for reference.
Thanks again for being my extra sets of eyes!

Public Sub Connect()
Sim clientSocket as Socket

clientSocket = New Socket(AddressFamily.InterNetwork, _
SocketType.Stream, ProtocolType.Tcp)

' Old code, based off of DNS Resolution
' Dim endpoint As IPEndPoint = _
' New IPEndPoint(Dns.Resolve(FRemoteHost).AddressList(0), _
' FRemotePort)

' New code, purely based off of IP address. In a more robust class, I
' might throw a RegEx in at this point so that either a hostname OR
' an IP address would work. 8^D
Dim IPAddr As IPAddress
IPAddr = IPAddr.Parse(FRemoteHost)

' Now continue as normal, connecting to the server
Dim endpoint As IPEndPoint = New IPEndPoint(IPAddr, 21)

Try
clientSocket.Connect(endpoint)
Catch ex As Exception
Throw New IOException("Connect failed", ex)
End Try

ReadResponse()
End Sub
 

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