PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > User to user Discussions > Programming the Internet

Programming the Internet Programming issues related to the Internet, including Winsock, CGI and ISAPI.

Reply
 
Thread Tools Display Modes
  #1  
Old Sep 27th, 2007, 02:31 PM
Roger Garstang Roger Garstang is offline
Member
 
Join Date: Feb 2003
Location: Wentzville, MO, USA
Posts: 1,825
Question FTP STOR Command

I made an application to connect out to a piece of hardware and update some files that just makes a direct connection to the device and sends commands. I'm doing pretty good with everything except this command. I connect Send USER, PASS, Set Type to A, issue PORT to tell it to come to a port around 1536 (I add a RND number 0-255 to it since multiple instances are running, and repeat this until I can open a port on both ends without error), then issue a LIST and get a list of files that I'm changing where I also grab sizes since SIZE isn't supported, then I set type to I (Only binary supported for file transfer) and get the files one by one with RETR and modify them (in memory) if needed and then I need to send them back. This is the point of failure.

The STOR command is issued and the server returns "150 STOR: Command accepted!", but I can't seem to make the connection. I've tried to connect to the server on the same port i told it to connect to me with the PORT command and tried to connect to port 20, but neither one can open, so I can't send the modified files back. The RFC wasn't much help...I gained more from watching the previous app I'm replacing/improving with WireShark. It appeared to send to the same Port as the PORT command set for client side. It issues a PORT command every time it does something though which didn't appear needed since it sends Directory info and files to me fine using just one PORT command, and I don't need more than one data channel.

Any suggestions/advice?
__________________
RG
Mobile Solutions
Sys Analyst and Development
Reply With Quote
  #2  
Old Sep 28th, 2007, 09:44 AM
Joe Byrne Joe Byrne is offline
Member
 
Join Date: Feb 2000
Location: Central Mn., USA
Posts: 4,930
Roger,

Generally speaking, the PORT command is not needed. This is normally used only when you need to get around limits imposed by a firewall. Assuming you are able to connect to the FTP server via port 21 (which is seems you are) then your client by default has established a working two-way communication. That is not to say that all is guaranteed to be perfect, but more than likely, you're good to go.

My guess is that you need to send the PASV command (Passive Mode) before sending your file.

Give that a whirl and see how it goes.
__________________
All those in favor of global warming, please raise your hands
Reply With Quote
  #3  
Old Sep 28th, 2007, 12:19 PM
Roger Garstang Roger Garstang is offline
Member
 
Join Date: Feb 2003
Location: Wentzville, MO, USA
Posts: 1,825
In FTP there has to be two ports open. One for commands and one for data- Results of a file request of a directory listing are sent over the data port. RFCs say port 20 is the default data port if PORT isn't used, but that doesn't seem to be the case here. PASV is somewhat the opposite of PORT, instead of sending the server a port that you want it to connect back on, you request a port to connect to on the server, so the client doesn't have firewall issues since it would then initiate the connection for both command and data ports. Unfortunately PASV isn't supported by this hardware, so PORT has to do. And, since Port 20 doesn't appear to be the default I have to use PORT to tell it what to use. This works fine for Receiving the file and directory list, but I can't seem to figure out how PORT applies/is used with STOR. It also appears that the hardware is dumb and if I can't connect to it after requesting STOR it then deletes the file...which is very bad since once the hardware reboots it can't make a network connection, so cannot be fixed remotely. I've tried to connect to the server to send the file both on the port specified in PORT and to port 20, but neither will connect.
__________________
RG
Mobile Solutions
Sys Analyst and Development
Reply With Quote
  #4  
Old Sep 28th, 2007, 03:41 PM
Joe Byrne Joe Byrne is offline
Member
 
Join Date: Feb 2000
Location: Central Mn., USA
Posts: 4,930
Ok, interesting server. Just a shot in the dark, but have you tried using the PUT command instead of STOR. Non-standard, but your server seems to be a bit non-standard too
__________________
All those in favor of global warming, please raise your hands
Reply With Quote
  #5  
Old Sep 28th, 2007, 03:56 PM
Roger Garstang Roger Garstang is offline
Member
 
Join Date: Feb 2003
Location: Wentzville, MO, USA
Posts: 1,825
Nope, no PUT command, that is usually HTTP anyway. Supported commands are: user, pass, quit, pwd, cwd, mkd, rmd, port, retr, cdup, stor, dele, rnfr, stru, noop, type, mode, help, syst, and site.

I analyzed with WireShark and noticed when it stores the server-side port isn't the one requested, but the client-side is...and the server appears to be the first to start the connection, so I guess it connects to me like the other commands. I'm going to have to change my data loop for that one. Sounds even more non-standard too since docs for STOR say PORT must be called before issued so the server knows what port to accept on. I guess I'll see what happens.
__________________
RG
Mobile Solutions
Sys Analyst and Development
Reply With Quote
  #6  
Old Oct 1st, 2007, 04:09 PM
Peter Redei Peter Redei is offline
Member
 
Join Date: Nov 1998
Location: San Pedro, CA
Posts: 422
If you use active connection create a socket for listening and tell the FTP server what is this socket with the PORT command (pass a (portstring'). The FTP server should either answer with a 200 (success) or a 500 (not understood) reply on the communication socket. Now, you issue the STOR command and pass the path of the file to upload (don't forget to put $CRLF to the end). The FTP Server will reply with 150 (opening binary connection) or with 553 (permission denied). Upon 150 reply the server will start to pump the data. You should know what is the size of the file you want to receive and when to close the opened file and than the socket.

If you use passive connection you issue a PASV command first. The server will reply with 227 and passing you a 'portstring' that you need to decode. Now, you know where to pump the data. Open a data socket for the IP/Port from the 'portstring'. The server will accept the socket. Now, you issue the STOR command passing the path to the file to upload. The leftover is the same as for active connection. Don Dickerson wrote PB code that is available in this forum.

I hope this helps.


Regards,


Peter Redei
Reply With Quote
  #7  
Old Oct 1st, 2007, 05:24 PM
Roger Garstang Roger Garstang is offline
Member
 
Join Date: Feb 2003
Location: Wentzville, MO, USA
Posts: 1,825
Yeah, I think I finally got it to work. The documents on FTP made it sound like I make the connection to send to the server, but it connects to me as with the other commands and then I send data to it. I had to modify my loop that processes the data line a little, but it seems to be functional now. One nice addition to the TCP commands in PB would be a command like FREEFILE, but reports a free port, that way I wouldn't have to loop on err until a good port is found to HOST on.
__________________
RG
Mobile Solutions
Sys Analyst and Development
Reply With Quote
Reply

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:25 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1999-2011 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit