Repost: FTP and the Compact Framework

P

Paul Eden

Hi

I'm reposting this as I'm kind of desperate for any thoughts - not
becasue of impatience. Any input would be greatly apprieciated.


Many thanks

Paul
Hi all

I recently managed to find a proven piece of code from these groups,
for using FTP on the Compact Framework. It was originally written for
the desktop but a respected name (can't remember who) said that he had
got it working on PDA by commenting out a line.
I tried it and at was great - connected to ftp site almost first time.
I now have a prblem though. The code does work 100% on the desktop,
but the PORT command always fails on the PDA. I was wondering if
anyone could shed any light on this. I currently have the PDA 'sunk'
with the desktop via a cradle and I'm attempting to connect to a an
FTP server on me local machine. Could this setup prevent the PORT
command from succeding, or are there a restricted number or ports
available to use on the PDA and my port number is too high?
I have lokoed into IPworks, but the cost is too high as their
component does 101 things.. but I only need one bit of it, so it's not
cost effective for us.

The code for setting the port is as follows (not originally written by
me, I just put it in it's own proc and added a couple of bits):


/// <summary>
/// Function to find usable IPaddress and port number for FTP
return path
/// </summary>
/// <returns>
/// Arraylist[0]=Ipaddress object
/// Arraylist[1]=port number as integer
/// </returns>
public ArrayList SetPort()
{
string sOut = null;
string returnString=null;
bool bIPFound = false;
ArrayList returnValue=new ArrayList();

// get a list of IP addresses for this machine
IPHostEntry ipThis = Dns.GetHostByName(Dns.GetHostName());
Random r = new Random();
// we will try all IP addresses assigned to this machine
// the first one that the remote machine likes will be chosen
while (!bIPFound)
{
for(int i=0;i<ipThis.AddressList.Length;i++)
{
string ip =
ipThis.AddressList.ToString().Replace(".",",");
int p1 = r.Next(20);
int p2 = r.Next(20);
p_Port = 256*p1+p2;
string sPortCom = "PORT " + ip + "," +
p1.ToString() + "," +
p2.ToString();
// Port command now looks like PORT
61,45,6,34,xx,yy where
// first 4 values is your IP address and xx and yy
are random numbers
// 256*xx+yy will be the port number where the
remote machine will connect
// and send data
WriteToStream(sPortCom);
sOut = m_comRead.ReadLine();

RaiseInfoEvent(sOut);

returnString = string.Concat(sOut + " - " +
sPortCom + "\r\n",returnString);
if (sOut.Substring(0,3) == "200")
{
// PORT command accepted
bIPFound = true;
returnValue.Add(ipThis.AddressList);
returnValue.Add(p_Port);
break;
}
}
}

return returnValue;

}


The 'While...' is there because on the desktop I found that sometime
the command failed, but retrying succeded.


Appologies for any line wrapping.. I was sifting through it trying to
ensure no wraps, until I learnt that C# can be multi-line (I'm VB).

Any input would be useful.


Many thanks


Paul
 
G

Guest

What do you mean by fails?

What error do you get?

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org
My blog: http://blog.opennetcf.org/ayakhnin

Paul Eden said:
Hi

I'm reposting this as I'm kind of desperate for any thoughts - not
becasue of impatience. Any input would be greatly apprieciated.


Many thanks

Paul
Hi all

I recently managed to find a proven piece of code from these groups,
for using FTP on the Compact Framework. It was originally written for
the desktop but a respected name (can't remember who) said that he had
got it working on PDA by commenting out a line.
I tried it and at was great - connected to ftp site almost first time.
I now have a prblem though. The code does work 100% on the desktop,
but the PORT command always fails on the PDA. I was wondering if
anyone could shed any light on this. I currently have the PDA 'sunk'
with the desktop via a cradle and I'm attempting to connect to a an
FTP server on me local machine. Could this setup prevent the PORT
command from succeding, or are there a restricted number or ports
available to use on the PDA and my port number is too high?
I have lokoed into IPworks, but the cost is too high as their
component does 101 things.. but I only need one bit of it, so it's not
cost effective for us.

The code for setting the port is as follows (not originally written by
me, I just put it in it's own proc and added a couple of bits):


/// <summary>
/// Function to find usable IPaddress and port number for FTP
return path
/// </summary>
/// <returns>
/// Arraylist[0]=Ipaddress object
/// Arraylist[1]=port number as integer
/// </returns>
public ArrayList SetPort()
{
string sOut = null;
string returnString=null;
bool bIPFound = false;
ArrayList returnValue=new ArrayList();

// get a list of IP addresses for this machine
IPHostEntry ipThis = Dns.GetHostByName(Dns.GetHostName());
Random r = new Random();
// we will try all IP addresses assigned to this machine
// the first one that the remote machine likes will be chosen
while (!bIPFound)
{
for(int i=0;i<ipThis.AddressList.Length;i++)
{
string ip =
ipThis.AddressList.ToString().Replace(".",",");
int p1 = r.Next(20);
int p2 = r.Next(20);
p_Port = 256*p1+p2;
string sPortCom = "PORT " + ip + "," +
p1.ToString() + "," +
p2.ToString();
// Port command now looks like PORT
61,45,6,34,xx,yy where
// first 4 values is your IP address and xx and yy
are random numbers
// 256*xx+yy will be the port number where the
remote machine will connect
// and send data
WriteToStream(sPortCom);
sOut = m_comRead.ReadLine();

RaiseInfoEvent(sOut);

returnString = string.Concat(sOut + " - " +
sPortCom + "\r\n",returnString);
if (sOut.Substring(0,3) == "200")
{
// PORT command accepted
bIPFound = true;
returnValue.Add(ipThis.AddressList);
returnValue.Add(p_Port);
break;
}
}
}

return returnValue;

}


The 'While...' is there because on the desktop I found that sometime
the command failed, but retrying succeded.


Appologies for any line wrapping.. I was sifting through it trying to
ensure no wraps, until I learnt that C# can be multi-line (I'm VB).

Any input would be useful.


Many thanks


Paul

 
P

Paul [Paradise Solutions]

Thanks for the reply

Sorry forgot to write that bit in. Basicly it results in a '500'
response from the server meaning 'invalid port command' - I can't really
go into more detail than that, because that's all I know. The reason
it's bugging me so much is that the exact same code runs without failure
in the desktop. That's what made me wonder if there was something port
related inconjunction with using the cradle as it is a kind of NAT set
up (if I've understood it correctly).

Thanks



Paul
What do you mean by fails?

What error do you get?

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org
My blog: http://blog.opennetcf.org/ayakhnin

:

Hi

I'm reposting this as I'm kind of desperate for any thoughts - not
becasue of impatience. Any input would be greatly apprieciated.


Many thanks

Paul

Paul [Paradise Solutions] wrote:

Hi all

I recently managed to find a proven piece of code from these groups,
for using FTP on the Compact Framework. It was originally written for
the desktop but a respected name (can't remember who) said that he had
got it working on PDA by commenting out a line.
I tried it and at was great - connected to ftp site almost first time.
I now have a prblem though. The code does work 100% on the desktop,
but the PORT command always fails on the PDA. I was wondering if
anyone could shed any light on this. I currently have the PDA 'sunk'
with the desktop via a cradle and I'm attempting to connect to a an
FTP server on me local machine. Could this setup prevent the PORT
command from succeding, or are there a restricted number or ports
available to use on the PDA and my port number is too high?
I have lokoed into IPworks, but the cost is too high as their
component does 101 things.. but I only need one bit of it, so it's not
cost effective for us.

The code for setting the port is as follows (not originally written by
me, I just put it in it's own proc and added a couple of bits):


/// <summary>
/// Function to find usable IPaddress and port number for FTP
return path
/// </summary>
/// <returns>
/// Arraylist[0]=Ipaddress object
/// Arraylist[1]=port number as integer
/// </returns>
public ArrayList SetPort()
{
string sOut = null;
string returnString=null;
bool bIPFound = false;
ArrayList returnValue=new ArrayList();

// get a list of IP addresses for this machine
IPHostEntry ipThis = Dns.GetHostByName(Dns.GetHostName());
Random r = new Random();
// we will try all IP addresses assigned to this machine
// the first one that the remote machine likes will be chosen
while (!bIPFound)
{
for(int i=0;i<ipThis.AddressList.Length;i++)
{
string ip =
ipThis.AddressList.ToString().Replace(".",",");
int p1 = r.Next(20);
int p2 = r.Next(20);
p_Port = 256*p1+p2;
string sPortCom = "PORT " + ip + "," +
p1.ToString() + "," +
p2.ToString();
// Port command now looks like PORT
61,45,6,34,xx,yy where
// first 4 values is your IP address and xx and yy
are random numbers
// 256*xx+yy will be the port number where the
remote machine will connect
// and send data
WriteToStream(sPortCom);
sOut = m_comRead.ReadLine();

RaiseInfoEvent(sOut);

returnString = string.Concat(sOut + " - " +
sPortCom + "\r\n",returnString);
if (sOut.Substring(0,3) == "200")
{
// PORT command accepted
bIPFound = true;
returnValue.Add(ipThis.AddressList);
returnValue.Add(p_Port);
break;
}
}
}

return returnValue;

}


The 'While...' is there because on the desktop I found that sometime
the command failed, but retrying succeded.


Appologies for any line wrapping.. I was sifting through it trying to
ensure no wraps, until I learnt that C# can be multi-line (I'm VB).

Any input would be useful.


Many thanks


Paul

 
P

Paul G. Tobey [eMVP]

That sounds like a problem with the ActiveSync 'network' communication. Can
you try it with a real network adapter?

Paul T.

Paul said:
Thanks for the reply

Sorry forgot to write that bit in. Basicly it results in a '500' response
from the server meaning 'invalid port command' - I can't really go into
more detail than that, because that's all I know. The reason it's bugging
me so much is that the exact same code runs without failure in the
desktop. That's what made me wonder if there was something port related
inconjunction with using the cradle as it is a kind of NAT set up (if I've
understood it correctly).

Thanks



Paul
What do you mean by fails?

What error do you get?

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org
My blog: http://blog.opennetcf.org/ayakhnin

:

Hi

I'm reposting this as I'm kind of desperate for any thoughts - not
becasue of impatience. Any input would be greatly apprieciated.


Many thanks

Paul

Paul [Paradise Solutions] wrote:


Hi all

I recently managed to find a proven piece of code from these groups, for
using FTP on the Compact Framework. It was originally written for the
desktop but a respected name (can't remember who) said that he had got
it working on PDA by commenting out a line.
I tried it and at was great - connected to ftp site almost first time. I
now have a prblem though. The code does work 100% on the desktop, but
the PORT command always fails on the PDA. I was wondering if anyone
could shed any light on this. I currently have the PDA 'sunk' with the
desktop via a cradle and I'm attempting to connect to a an FTP server on
me local machine. Could this setup prevent the PORT command from
succeding, or are there a restricted number or ports available to use on
the PDA and my port number is too high?
I have lokoed into IPworks, but the cost is too high as their component
does 101 things.. but I only need one bit of it, so it's not cost
effective for us.

The code for setting the port is as follows (not originally written by
me, I just put it in it's own proc and added a couple of bits):


/// <summary>
/// Function to find usable IPaddress and port number for FTP
return path
/// </summary>
/// <returns>
/// Arraylist[0]=Ipaddress object
/// Arraylist[1]=port number as integer
/// </returns>
public ArrayList SetPort()
{
string sOut = null;
string returnString=null;
bool bIPFound = false;
ArrayList returnValue=new ArrayList();

// get a list of IP addresses for this machine
IPHostEntry ipThis = Dns.GetHostByName(Dns.GetHostName());
Random r = new Random();
// we will try all IP addresses assigned to this machine
// the first one that the remote machine likes will be
chosen
while (!bIPFound)
{
for(int i=0;i<ipThis.AddressList.Length;i++)
{
string ip =
ipThis.AddressList.ToString().Replace(".",",");
int p1 = r.Next(20);
int p2 = r.Next(20);
p_Port = 256*p1+p2;
string sPortCom = "PORT " + ip + "," + p1.ToString()
+ "," +
p2.ToString();
// Port command now looks like PORT 61,45,6,34,xx,yy
where
// first 4 values is your IP address and xx and yy
are random numbers
// 256*xx+yy will be the port number where the
remote machine will connect
// and send data
WriteToStream(sPortCom);
sOut = m_comRead.ReadLine();

RaiseInfoEvent(sOut);

returnString = string.Concat(sOut + " - " + sPortCom
+ "\r\n",returnString);
if (sOut.Substring(0,3) == "200")
{
// PORT command accepted
bIPFound = true;
returnValue.Add(ipThis.AddressList);
returnValue.Add(p_Port);
break;
}
}
}
return returnValue;

}


The 'While...' is there because on the desktop I found that sometime the
command failed, but retrying succeded.


Appologies for any line wrapping.. I was sifting through it trying to
ensure no wraps, until I learnt that C# can be multi-line (I'm VB).

Any input would be useful.


Many thanks


Paul
 
P

Paul [Paradise Solutions]

Not easiy, although I'm faffing with a wireless adapter at the moment so
hopefully I can take advantage of that and test it that way - I'm glad
it sounds like AS problem rather than an issue with my teef'd code.

Thanks for the reply



Paul


That sounds like a problem with the ActiveSync 'network' communication. Can
you try it with a real network adapter?

Paul T.

Thanks for the reply

Sorry forgot to write that bit in. Basicly it results in a '500' response
from the server meaning 'invalid port command' - I can't really go into
more detail than that, because that's all I know. The reason it's bugging
me so much is that the exact same code runs without failure in the
desktop. That's what made me wonder if there was something port related
inconjunction with using the cradle as it is a kind of NAT set up (if I've
understood it correctly).

Thanks



Paul
What do you mean by fails?

What error do you get?

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org
My blog: http://blog.opennetcf.org/ayakhnin

:



Hi

I'm reposting this as I'm kind of desperate for any thoughts - not
becasue of impatience. Any input would be greatly apprieciated.


Many thanks

Paul

Paul [Paradise Solutions] wrote:



Hi all

I recently managed to find a proven piece of code from these groups, for
using FTP on the Compact Framework. It was originally written for the
desktop but a respected name (can't remember who) said that he had got
it working on PDA by commenting out a line.
I tried it and at was great - connected to ftp site almost first time. I
now have a prblem though. The code does work 100% on the desktop, but
the PORT command always fails on the PDA. I was wondering if anyone
could shed any light on this. I currently have the PDA 'sunk' with the
desktop via a cradle and I'm attempting to connect to a an FTP server on
me local machine. Could this setup prevent the PORT command from
succeding, or are there a restricted number or ports available to use on
the PDA and my port number is too high?
I have lokoed into IPworks, but the cost is too high as their component
does 101 things.. but I only need one bit of it, so it's not cost
effective for us.

The code for setting the port is as follows (not originally written by
me, I just put it in it's own proc and added a couple of bits):


/// <summary>
/// Function to find usable IPaddress and port number for FTP
return path
/// </summary>
/// <returns>
/// Arraylist[0]=Ipaddress object
/// Arraylist[1]=port number as integer
/// </returns>
public ArrayList SetPort()
{
string sOut = null;
string returnString=null;
bool bIPFound = false;
ArrayList returnValue=new ArrayList();

// get a list of IP addresses for this machine
IPHostEntry ipThis = Dns.GetHostByName(Dns.GetHostName());
Random r = new Random();
// we will try all IP addresses assigned to this machine
// the first one that the remote machine likes will be
chosen
while (!bIPFound)
{
for(int i=0;i<ipThis.AddressList.Length;i++)
{
string ip =
ipThis.AddressList.ToString().Replace(".",",");
int p1 = r.Next(20);
int p2 = r.Next(20);
p_Port = 256*p1+p2;
string sPortCom = "PORT " + ip + "," + p1.ToString()
+ "," +
p2.ToString();
// Port command now looks like PORT 61,45,6,34,xx,yy
where
// first 4 values is your IP address and xx and yy
are random numbers
// 256*xx+yy will be the port number where the
remote machine will connect
// and send data
WriteToStream(sPortCom);
sOut = m_comRead.ReadLine();

RaiseInfoEvent(sOut);

returnString = string.Concat(sOut + " - " + sPortCom
+ "\r\n",returnString);
if (sOut.Substring(0,3) == "200")
{
// PORT command accepted
bIPFound = true;
returnValue.Add(ipThis.AddressList);
returnValue.Add(p_Port);
break;
}
}
}
return returnValue;

}


The 'While...' is there because on the desktop I found that sometime the
command failed, but retrying succeded.


Appologies for any line wrapping.. I was sifting through it trying to
ensure no wraps, until I learnt that C# can be multi-line (I'm VB).

Any input would be useful.


Many thanks


Paul

 

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