Dare2 wrote:Hi Terry,
Thanks for the update.
As I understand it, if PASV and PORT are not issued, PORT is assumed on port 20. So I was wondering why PORT cannot be used in "default" mode rather than via an explicit approach, that is, just assume 20
You're welcome. Hope it is useful.
You are correct the PORT is assumed on port 20 (per the RFCs).
And the PORT method should be the "default" mode to use.
However, assuming anything about how some of the servers work
backfires on me frequently. So, I made it more explicit. Hopefully,
if I tell the server how I want to communicate it will comply.
Also, working with PORT behind a router requires that the router
"forward" the incoming requests properly. So, if you are attempting
this behind a router or firewall, make sure the PORT range is being
forwarded correctly.
In this code, I used a range of 20 ports starting at 6000 It probably
could be port 20 alone just as easily. The PB references for
CreateNetworkServer says
Create a new network server on the local computer at the specified port. Port values can range from 6000 to 7000 (this is a recommended area space, but it can go from 0 to 65000 in reality).
but it doesn't appear to be a real restriction.
NOTE: A problem I expericence: When I use CloseNetworkServer()
it seems that the port is not closed immediately even though the
program continues immediately. Since CloseNetworkServer() doesn't
return a response, I can't capture that occurance. So, if I try to
CreateNetworkServer() on that same port again, there are problems.
I got around that by using random ports in the defined 20 port range.
Not sure whether it is my problem or a bug in PB's CloseNetworkServer()
or just a timing issue.
Personally, I prefer the PASV mode because the Client Program does not
have to act as a server at all. Much simpler and that should be more
secure.
So, why did I go to the effort to try to make PORT work when I already
had PASV working well?
1) To see if I could

I wanted the code to work pretty generically.
2) Because the server software(s) I tested with are very inconsistent in
how thay assign the port to be used which created problems for my
intended use. Some servers assign random ports which may not be
open for use when they are running behind a router (my case). Another
assigns PASV ports withing a definable range, using the first port number
over and over unless the server knows that it is still open in which case it
increments the port number by one. That was not a real problem for me,
but that same server just doesn't function at all with the PORT method.
Another server requires the client to connect using the full IP address of
the server with the assigned port number, but issues the local LAN IP
address in the PASV reponse when it is running behinc a router instead of
the visible WAN IP address. In that case, the client can't locate the server
to send/receive the files.
It has been fun and a good learning process for me. I am sure I will
continue to tweak this code for some time.
Keep me posted on how things are working for you.
Terry