FTP Ports
FTP Ports
FTP Ports
FTP Ports
FTP Ports
FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports
FTP Ports FTP Ports
FTP Ports
Go Back  Xtreme Visual Basic Talk > > > FTP Ports


Reply
 
Thread Tools Display Modes
  #1  
Old 01-03-2008, 08:31 AM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default FTP Ports


Hi all
Can anyone help with this please?
I've written a client that FTP's image files to an FTP server (from 1 to 6 images at a time) using the Inet control. I do execute a loop waiting for StillExecuting to be false (a timer is used to branch out if there is a long delay - the user can elect to keep on trying)
This all works fine. The problem is, if I then try to send up another batch shortly afterwards, the transmission often fails (no error message despite error trapping) and VB6 crashes. I've checked to make sure that the FTP connection is closed after each upload batch.
On this second transmission there isn't a standard place where it crashes either, sometimes it will initialise the inet control other times it will send one or two images.
I read somewhere I think that the FTP port can remain "locked up" for a while (up to 4 minutes if I remember correctly). Is this true- or was this eyewash? Certainly if I leave it for a while and try again it works (once) - but then of course I've had to restart vb and my vbapp.
If it is true, do you think a locked up port is my problem?
Should I therefore select a different port for each upload - and which ports are "free"?
I've simplified somewhat what is actually occurring, client is also sometimes initiating CD, DIR and Deletes too on the server (although none of these give any problems either on the first batch).
Many thanks for any help here.
Regards
Dave
Reply With Quote
  #2  
Old 01-03-2008, 09:15 AM
Robert Collins Robert Collins is offline
Contributor
 
Join Date: May 2004
Posts: 695
Default

I would think that you should use a different port for each transmission. I used to start out with some very high port number, like 7000 for example, and then on each transmission I would increment the port by about 5 (not an absolute neccessity that it be 5) or some other value. I kind of remember that you will have problems by using the same port number each time.
Reply With Quote
  #3  
Old 01-03-2008, 09:24 AM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

Hi Robert
Many thanks for that - I'll do as you have suggested and let you know. And thanks for such a speedy reply.
Regards
Dave
Reply With Quote
  #4  
Old 01-03-2008, 09:59 AM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

Ah! A problem with that solution. Firstly the FTP server will not respond to my port 7000, which is academic really as thinking about it: there is no way I can expect the customers of this app to fiddle around with their firewall exception settings for at least 10 ports.
So here's another question all: If upon startup of my app, I initialise the Inet control for FTP and leave it as such until the app closes (so just a single connection throughout) what are the ramifications of this? I could be talking about (in extreme cases) my app being open for a day or two!
Any thoughts/help(/donations )
Thanks
Dave
Reply With Quote
  #5  
Old 01-03-2008, 10:50 AM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

Leaving the connection open would be fine as long as you are only connecting 1 app at a time. If you plan to have about 50 users connected then its not recommended. You also have to be carefull of the server resetting the connection due to a timeout. You have to send NOOP (no-op. Do nothing but reset the timout)
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #6  
Old 01-03-2008, 11:28 AM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

Thanks Master
That's all very useful. I can't think of another way around the problem, so it may be that we will have to use several ftp servers as we are expecting several hundred users.
Thanks again
Dave
Reply With Quote
  #7  
Old 01-03-2008, 11:30 AM
Robert Collins Robert Collins is offline
Contributor
 
Join Date: May 2004
Posts: 695
Default

Unless the port number is a reserved port (and I don't think 7000 is reserved) an FTP server should respond on any port you specify. However, didn't you at least make one good FTP session? If so, then use that port numer as the starting point and increment it on each session thereafter. In any event using different port numbers is recommended especially if you are FTP'ing one after another. You might try doing one FTP at a time and making sure it has successfuly completed before you do another using a different port number. Right off the top of my head I can't see why the server wouldn't respond on port 7000. Try other port numbers.

Like DJ stated, FTP clients will send some command to keep the connection alive. Usual commands are NOOP, PWD, or any command that doesn't invoke a transmission of data. Also, are you able to see the server responses? It really helps to know what the server is thinking. Also, like DJ pointed out you cannot have one session running all day long and have other users using that same session. You know, I think that servers will eventually disconnect you anyway after a certain amount of time. The server doesn't want you to monopolize the bandwidth.

NOTE

There's nothing wrong with making an FTP connection, doing a session, and then dissconnect and then re-connect again.

Last edited by Robert Collins; 01-03-2008 at 11:34 AM. Reason: Additional Info
Reply With Quote
  #8  
Old 01-03-2008, 12:06 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

I wonder if this has anything to do with the long discussion we had in another thread about using 0 as local port with winsock. It definately sounds similar but i dont think you can do anything to fix that.

In your case you cant change the port. You could set a different port like 7000 but then you are stuck with 7000. Incrementing by 5 would require you to reprogram the FTP server with some kind of complicated synchronization or have multiple instances of the FTP server app running. Neither are desireable.

Are you closing the connection properly after an upload?
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #9  
Old 01-03-2008, 12:19 PM
Robert Collins Robert Collins is offline
Contributor
 
Join Date: May 2004
Posts: 695
Default

You could set a different port like 7000 but then you are stuck with 7000. Incrementing by 5 would require you to reprogram the FTP server with some kind of complicated synchronization or have multiple instances of the FTP server app running.

I don't understand that one, DJ. In all my FTP programs I have written I have always used incrementing port numbers. It had nothing to do with the server, only the client. It's common pratice to have different port numbers for each session. Even in a single session but doing multiple FTPs require a different port number. Servers don't really care what port number you use as long as it is not a reserved port, so simply try port numbers until the server is happy. If you can't find port numbers that work then there is something else going on that is causing this to happen.
Reply With Quote
  #10  
Old 01-03-2008, 12:28 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

If the server is listening on port 21 (default) then you cant open a connection to it on port 22
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #11  
Old 01-03-2008, 12:44 PM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

Thanks both of you for your valuable input. Yes DJ I'm closing the connection properly.
The thing about using other ports is really academic however as we cannot realistically expect the end user to tune their firewalls to suit. So we are stuck with either a long connection time or finding some way of forcing the port to release, which it simply seems to refuse to do (from what I can remember reading - this won't happen until some deep-rooted stuff in Windows tells it that's its ok to release - some such nonsense - and supposedly this can take up to 4 minutes! (although normally much quicker one assumes)


It's a difficult one to trap for too because it's not raising an error. It just seems to get itself into a helpless hang and eventually crashes - taking vb6 with it! It seems to get past the initialise bit, but try to get it to execute anything and its as if it suddenly realises its still "open" from the previous connection and sulks lol.
Reply With Quote
  #12  
Old 01-03-2008, 12:48 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

I know what youve read about but im sure that applies to the local port. We had a long dicussion about it in another thread but i cant see how that can apply here (unless M$ programmed the control wrong)

Is it possible for you to upload your project and create a test account on your FTP server?
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #13  
Old 01-03-2008, 12:52 PM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

Sorry, when you say local port I assume you mean 21?
That is where I'm getting the problem - am I being dense here - lol
Reply With Quote
  #14  
Old 01-03-2008, 12:57 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

I still dont completely understand it myself but what i do know is that the server's local port is 21. Your application (the client) uses 21 as its remote port. When you connect through winsock your supposed to set the clients local port to 0 so it automatically gets a free local port (this isnt 21). Usually the clients localport stuff is handled for you and you dont realise but if the control you are using specifys a local port then it can take 4 mins for that to be released
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #15  
Old 01-03-2008, 01:35 PM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

I see what you are saying. I'm using the Inet control rather than winsock and there's no facility to select ports except the remote port (of course that's why setting 7000 didn't work - it's the remote port- duh). So obviously its handling the local port settings itself and that's what is causing the delay in release. I wonder if there's anything in the API that'll force the port closed (then again -from what you say, there is no definitive way of knowing what local port is being used - although looking at my firewall settings, it has an outbound exception on port 21 - (for ftp), so doesn't this say that it does allocate 21?
Reply With Quote
  #16  
Old 01-03-2008, 01:49 PM
Robert Collins Robert Collins is offline
Contributor
 
Join Date: May 2004
Posts: 695
Default

Port 21 is the remote port for FTP. The FTP server is listening on that port. Port 7000 or whatever port you use is the local port. You must tell the server what your port number is that you will be listening on so the server can send you data on that port or you can send data to the server on that same port. FTP works with two socket connections. One socket, on port 21, is the command channel and the other socket on port nnn (your choise within the allowable numbers) is the data channel that you send and recieve data on. When you are finished either send or recieving data on that port you need to use another port for your next session after you have disconnected from the server on your first session.

1) Connect to FTP server on Port 21
2) FTP server responds with ready command
3) Client establishes a port number and informs the server what that port number is
4) Server responds with OK or not OK
5) If OK, client either sends (PUT or STOR) or client recieves (GET or RETR) data on the data port.
6) If sending, clients closes the socket
7) If recieving server tells client that data is all sent and client then closes his connection

Return to step 1 forn next FTP session
Reply With Quote
  #17  
Old 01-03-2008, 01:51 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

The outbound port is 21. Remote port is the port your client uses to connect outwards. Your right, you dont have control of the local port with the inet control (i dont think) but the control should handle all that itself.

The other thread i was talking about can be found here

Are you using the inet API then? Maybe that has something to do with it. APIs are harder to use and its easier to cause problems
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #18  
Old 01-03-2008, 01:53 PM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,596
Default

Robert Collins. I see what you mean now. Using incrementing ports for the data socket.
__________________
"That which seems simple is often overlooked" ~ me
Halloween 2014 Yard Haunt
Halloween Special FX
Reply With Quote
  #19  
Old 01-03-2008, 02:39 PM
Dave Green Dave Green is offline
Freshman
 
Join Date: Oct 2005
Posts: 26
Default

Hi again DJ and Robert
I really appreciate the time you are putting to this. Firstly to answer you DJ, no I'm not using the API, just the basic Inet properties and methods. And that thread was the one where I read about the 4 minute thing originally (I wondered where I'd got it from). It makes sense now why they're kept open for so long.
Being as the Inet control exposes no facility for changing ports as Robert has suggested, would I be taking the right track by dumping the Inet control and switching to Winsock? If so, is it difficult to set up for FTP (I've not used winsock in years and I can't remember what it's like)?
Dave
Reply With Quote
  #20  
Old 01-03-2008, 02:40 PM
Robert Collins Robert Collins is offline
Contributor
 
Join Date: May 2004
Posts: 695
Default

You can open a connection to a FTP server on port 21. Then within one session (not closing your local socket) you can send and recieve many times within that single session but you will still need to use a different port number for each data transfer (sending or recieving). After you have either sent many files or recieved many files and you are all done you then will close the socket. Wheather you open a new connection (on port 21) for each data transfer or you use a single connection for each data transfer does not matter to the server as long as you use a different data port number each time.

In using Winsock, you see this sort of handshaking going on and you are responsible in sending the correct commands to the server and responding to server responses in an orderly fashion. You use the PORT command to tell the server what port number you wish to use. But this is in Winsock and is probably done for you using Inet.

Using other means, like Inet, or some other higher level methods only means you do not need to do as much programming to acomplish the same results but you have less control also. FTP protocol is the same regardless of what method you use and all methods use the underlying Winsock API it 's just a matter of what fits you the best. I personally use the Winsock Control since it gives me a great deal of flexibility with not too difficultly in programming but others might prefer to use Inet or some other method.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
FTP Ports
FTP Ports
FTP Ports FTP Ports
FTP Ports
FTP Ports
FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports FTP Ports
FTP Ports
FTP Ports
 
FTP Ports
FTP Ports
 
-->