Using FTP Rest command

592 views
Skip to first unread message

Boguslaw Pazur

unread,
Jul 2, 2002, 5:34:16 AM7/2/02
to
Hello,
I try to use FTP Rest command to resume download file. My sequence is following:

InternetOpen - dwAccesType: INTERNET_OPEN_DIRECT, dwFlags: 0
InternetConnect - nServerPort: INTERNET_DEFAULT_FTP_PORT, dwService:
INTERNET_SERVICE_FTP, dwFlags: 0 (I try INTERNET_FLAG_PASSIVE, too, but
which value is correct?)
// Rest command: rest 1000
FtpCommand ( hFtp, FALSE, FTP_TRANSFER_TYPE_BINARY, RestCommand, NULL,
NULL )
// Retr command: retr example.exe
FtpCommand ( hFtp, TRUE, FTP_TRANSFER_TYPE_BINARY, RetrCommand, NULL,
hFileResume )
InternetReadFile - hFile: hFileResume

No errors are returned, but InternetReadFile read whole file (Rest command is
ignored).

TIA

Boguslaw Pazur

Alun Jones

unread,
Jul 2, 2002, 8:49:47 AM7/2/02
to
In article <79752a.020702...@posting.google.com>, bo...@mintech.pl
(Boguslaw Pazur) wrote:
>InternetOpen - dwAccesType: INTERNET_OPEN_DIRECT, dwFlags: 0
>InternetConnect - nServerPort: INTERNET_DEFAULT_FTP_PORT, dwService:
>INTERNET_SERVICE_FTP, dwFlags: 0 (I try INTERNET_FLAG_PASSIVE, too, but
>which value is correct?)
>// Rest command: rest 1000
>FtpCommand ( hFtp, FALSE, FTP_TRANSFER_TYPE_BINARY, RestCommand, NULL,
>NULL )
>// Retr command: retr example.exe
>FtpCommand ( hFtp, TRUE, FTP_TRANSFER_TYPE_BINARY, RetrCommand, NULL,
>hFileResume )
>InternetReadFile - hFile: hFileResume
>
>No errors are returned, but InternetReadFile read whole file (Rest command is
>ignored).

That's because you haven't sent a PORT or PASV command. WinInet isn't set up
to handle resuming interrupted file transfers, so you'd have to handle a
couple of unusual (for WinInet) things:

1. The REST command _must_ come immediately before the RETR command. This
means that you have to place it in between the PORT / PASV command and the
RETR command - and the function for retrieving files through FTP in WinInet
doesn't allow any option for this. I'm sure you're already aware of this,
because you've chosen to send individual FTP commands.

2. You have to send a PORT or PASV command, and interpret the result,
yourself. Additionally, you have to connect to the server (if you sent a PASV
command), or listen for the server to connect to you (if you sent a PORT
command) for the data connection, before you send the RETR command.

3. FtpCommand expects a single line response - RETR sends two lines in
response - one when it receives the command and starts sending the file, the
other when it has finished sending the file.

It's likely that you will find that WinInet is getting in your way more than
it is helping. There are likely to be other FTP libraries out there that you
can use, though, which would cope with more modern functionality than WinInet
offers.

Alun.
~~~~

[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Try WFTPD, the Windows FTP Server. Find us at
1602 Harvest Moon Place | http://www.wftpd.com or email al...@texis.com
Cedar Park TX 78613-1419 | VISA/MC accepted. NT-based sites, be sure to
Fax/Voice +1(512)258-9858 | read details of WFTPD Pro for NT.

hector santos

unread,
Jul 2, 2002, 1:50:26 PM7/2/02
to

"Boguslaw Pazur" <bo...@mintech.pl> wrote in message
news:79752a.020702...@posting.google.com...

You are not reading the response code from after issuing the "rest" command.

example pseudo code usage:

FtpCommand(, FALSE,,,,)
InternetGetLastResponse()

or

if (!FtpCommand(, TRUE,,,,hDataPort) hDataPort = NULL; // set NULL if
failed command
if (hDataPort) InternetReadFile(hDataPort,,,,,,)
InternetGetLastResponse()

ALWAYS call InternetGetLastResponse(), otherwise the state machine is out of
sync.

Also, The REST command is not always supported by the FTP Server. So you
need need to make
sure the command was successful by getting the xxx number from the response
line.

--
Hector Santos
Wildcat! Interactive Net Server
http://www.santronics.com

Boguslaw Pazur

unread,
Jul 3, 2002, 7:47:39 AM7/3/02
to
Thanks a lot Alun (and Hector Santos, too) for your help. But I still
have some problems.

> 2. You have to send a PORT or PASV command, and interpret the result,
> yourself. Additionally, you have to connect to the server (if you sent a PASV
> command), or listen for the server to connect to you (if you sent a PORT
> command) for the data connection, before you send the RETR command.

I try to use PASV and it seems to work OK. I get port number.
1) Should I use FtpCommand for PASV with fExpectResponse=TRUE. If yes
I get 2 ports. Which should be used?
Next I try to connect. I use InternetConnect with nServerPort set to
port returnded by PASV. But application hang up or InternetConnect
returns NULL. I try various combination but connection is never
established.
2) Where is problem?
3) I should connect to server "before you send the RETR command" i.e.
after REST before RETR?
4) For InternetReadFile should I use hFile from PASV or from RETR?

TIA

Boguslaw Pazur

hector santos

unread,
Jul 3, 2002, 8:08:51 AM7/3/02
to

"Boguslaw Pazur" <bo...@mintech.pl> wrote in message
news:79752a.020703...@posting.google.com...

> Thanks a lot Alun (and Hector Santos, too) for your help. But I still
> have some problems.

Looking at your original message...... Maybe the FTP Server doesn't support
REST?

> 2) Where is problem?
> 3) I should connect to server "before you send the RETR command" i.e.
> after REST before RETR?

REST first. But it could be ignored.

> 4) For InternetReadFile should I use hFile from PASV or from RETR?

Not sure what this means.

Reply all
Reply to author
Forward
0 new messages