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
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