Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Active FTP Connection


Best Answer StefanUSMC, 19 February 2013 - 02:58 AM

Not sure how to delete the post, but I figured it out. Sometimes the simplest solutions elude me. EndPoints can be cast ToString, and read clear as day. This is what I ended up doing:

 

LocalDataPort = int.Parse(CommandSocket.LocalEndPoint.ToString().Split(':')[1]) + 1;
Go to the full post


  • Please log in to reply
4 replies to this topic

#1 StefanUSMC

StefanUSMC

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts
  • LocationWisconsin, USA

Posted 19 February 2013 - 02:09 AM

Hello,

I currently have a project that will require me to exchange files via FTP. I have to run both a client and server, and both will need to utilize active FTP. I have read up on FTP, and believe I have a fairly good understanding of active vs passive. It would appear that my client will have to issue a PORT command, informing the server as to which data port to connect to. From what I have read, typically the data port on the client is the command port +1. How would I find what port a connection is open? What I have is:

 

private static Socket CommandSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);        private static Socket DataSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);        private static int DataPort;        public static void SendFile()        {            string RemoteHost = "192.168.1.44";            int RemotePort = 21;            IPAddress RemoteServerIP = IPAddress.Parse(RemoteHost);            IPEndPoint RemoteServerCmdEP = new IPEndPoint(RemoteServerIP, RemotePort);            try            {                Debug.Print("Starting Connection");                CommandSocket.Connect(RemoteServerCmdEP);                Debug.Print("Connected");            }

 

I know that I am connecting to port 21 on the remote end, but how can I see which port on the ND is utilized to make that connection? I assume that is will be somewhere in CommandSocket.LocalEndpoint, but I cannot seem to find it.

 

Thanks,

Brandon



#2 StefanUSMC

StefanUSMC

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts
  • LocationWisconsin, USA

Posted 19 February 2013 - 02:58 AM   Best Answer

Not sure how to delete the post, but I figured it out. Sometimes the simplest solutions elude me. EndPoints can be cast ToString, and read clear as day. This is what I ended up doing:

 

LocalDataPort = int.Parse(CommandSocket.LocalEndPoint.ToString().Split(':')[1]) + 1;


#3 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 19 February 2013 - 02:28 PM

i read somewhere the netduino doesent accept multiple connections (only one at a time)

- does it allready work for you ? (the ftp stuff with 2 connections)



#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 February 2013 - 03:06 PM

i read somewhere the netduino doesent accept multiple connections (only one at a time)

- does it allready work for you ? (the ftp stuff with 2 connections)

 

The netduino does support multiple connections with it's onboard ethernet. I know the wifly driver doesn't though. Maybe that's why you thought so?


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 19 February 2013 - 03:24 PM

idk where i got that, thx 4 info.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.