Discussion:
FTP Stuff
(too old to reply)
John Simmons
2005-04-16 14:28:10 UTC
Permalink
I'm writing a specialized FTP client that basically synchronizes files
between a server and a client. I've tried a number of methods for
retrieving the file date/time stamp from a couple of servers.

One server is my web-hosting site (referred to as the "remote server"
from this point), and the other is a local FileZilla server running on
Win2K (referred to as "local server" from this point).

The remote server returns the correct date, but the time is always
midnight, no matter what file I choose.

The local server returns what appears to be the file date/time based on
GMT.

When I connect to EITHER server with another FTP client, the file
date/time stamps are displayed normally (the times are what I would
expect).

What should I be doing to retrieve the date/time stamp?
Brian Cryer
2005-04-17 09:46:46 UTC
Permalink
Post by John Simmons
I'm writing a specialized FTP client that basically synchronizes files
between a server and a client. I've tried a number of methods for
retrieving the file date/time stamp from a couple of servers.
One server is my web-hosting site (referred to as the "remote server"
from this point), and the other is a local FileZilla server running on
Win2K (referred to as "local server" from this point).
The remote server returns the correct date, but the time is always
midnight, no matter what file I choose.
The local server returns what appears to be the file date/time based on
GMT.
When I connect to EITHER server with another FTP client, the file
date/time stamps are displayed normally (the times are what I would
expect).
What should I be doing to retrieve the date/time stamp?
I'm not aware of a problem with WinInet, but two things to check:

1. FtpFindFirstFile/InternetFindNextFile give you file times in
ftLastWriteTime, ftCreationTime and ftLastAccessTime. Its been a while since
I last looked at this, but my code uses ftLastWriteTime because I found the
others unreliable - I seem to recall they just returned 0, which wouldn't
account for you loosing the time portion.

2. Once you have the ftLastWriteTime value for a file, what are you doing
with it to convert it to a date/time string? i.e is there any likelihood
that the problem is in your code. Could you post this bit of your code for
people to look at?

regards,

Brian.

www.cryer.co.uk/brian
John Simmons
2005-04-18 09:34:12 UTC
Permalink
Post by Brian Cryer
Post by John Simmons
I'm writing a specialized FTP client that basically synchronizes files
between a server and a client. I've tried a number of methods for
retrieving the file date/time stamp from a couple of servers.
One server is my web-hosting site (referred to as the "remote server"
from this point), and the other is a local FileZilla server running on
Win2K (referred to as "local server" from this point).
The remote server returns the correct date, but the time is always
midnight, no matter what file I choose.
The local server returns what appears to be the file date/time based on
GMT.
When I connect to EITHER server with another FTP client, the file
date/time stamps are displayed normally (the times are what I would
expect).
What should I be doing to retrieve the date/time stamp?
1. FtpFindFirstFile/InternetFindNextFile give you file times in
ftLastWriteTime, ftCreationTime and ftLastAccessTime. Its been a while since
I last looked at this, but my code uses ftLastWriteTime because I found the
others unreliable - I seem to recall they just returned 0, which wouldn't
account for you loosing the time portion.
2. Once you have the ftLastWriteTime value for a file, what are you doing
with it to convert it to a date/time string? i.e is there any likelihood
that the problem is in your code. Could you post this bit of your code for
people to look at?
regards,
Brian.
www.cryer.co.uk/brian
Well, I'm not actually using wininet. I'm using the Dundas
UltimateTCP/IP toolkit, but I'm seriously considering switching to
wininet...
Murugan Andezuthu Dharmaratnam
2005-04-18 23:18:42 UTC
Permalink
Hi John,
Try WinHTTP , I started with WinInet and switched to WinHTTP this is if u
are planning to write a Windows NT service for your project. WinInet canoot
be used with Windows NT service. Looks to me it would be a good idea to
write the code as a an NT Service.

Thanks!
Murugan Andezuthu dharmaratnam
www.muruganad.net

"Nothing is impossible its just Improbable"
Post by John Simmons
Post by Brian Cryer
Post by John Simmons
I'm writing a specialized FTP client that basically synchronizes files
between a server and a client. I've tried a number of methods for
retrieving the file date/time stamp from a couple of servers.
One server is my web-hosting site (referred to as the "remote server"
from this point), and the other is a local FileZilla server running on
Win2K (referred to as "local server" from this point).
The remote server returns the correct date, but the time is always
midnight, no matter what file I choose.
The local server returns what appears to be the file date/time based on
GMT.
When I connect to EITHER server with another FTP client, the file
date/time stamps are displayed normally (the times are what I would
expect).
What should I be doing to retrieve the date/time stamp?
1. FtpFindFirstFile/InternetFindNextFile give you file times in
ftLastWriteTime, ftCreationTime and ftLastAccessTime. Its been a while since
I last looked at this, but my code uses ftLastWriteTime because I found the
others unreliable - I seem to recall they just returned 0, which wouldn't
account for you loosing the time portion.
2. Once you have the ftLastWriteTime value for a file, what are you doing
with it to convert it to a date/time string? i.e is there any likelihood
that the problem is in your code. Could you post this bit of your code for
people to look at?
regards,
Brian.
www.cryer.co.uk/brian
Well, I'm not actually using wininet. I'm using the Dundas
UltimateTCP/IP toolkit, but I'm seriously considering switching to
wininet...
Murugan Andezuthu Dharmaratnam
2005-04-18 02:00:13 UTC
Permalink
Hi John Simon,
I have done something similar to check if file is downloadeble by parts
using WinHTTP , Was writing this for a Distributed HTTP/FTP File Downloader
, Its similar to WinInet . I find the size of the file by adding an
additional header and using WinHttpQueryHeaders() Here is attached sample
code from MSDN.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winhttp/http/winhttpaddrequestheaders.asp

DWORD dwSize = sizeof(DWORD);
DWORD dwStatusCode = 0;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;

// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"A WinHTTP Example Program/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0 );

// Specify an HTTP server.
if( hSession )
hConnect = WinHttpConnect( hSession,
L"www.microsoft.com",
INTERNET_DEFAULT_HTTP_PORT,
0 );

// Create an HTTP Request handle.
if( hConnect )
hRequest = WinHttpOpenRequest( hConnect,
L"GET",
NULL,
NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
0 );

// Add a request header.
if( hRequest )
bResults = WinHttpAddRequestHeaders( hRequest,
L"If-Modified-Since: Mon, 20 Nov 2000 20:00:00 GMT",
-1,
WINHTTP_ADDREQ_FLAG_ADD );

// Send a Request.
if( bResults )
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
WINHTTP_NO_REQUEST_DATA,
0,
0,
0 );

// End the request.
if( bResults )
bResults = WinHttpReceiveResponse( hRequest, NULL);

// Use WinHttpQueryHeaders to obtain the header buffer.
if( bResults )
bResults = WinHttpQueryHeaders( hRequest,
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
NULL,
&dwStatusCode,
&dwSize,
WINHTTP_NO_HEADER_INDEX );

// Based on the status code, determine whether the document was recently
updated.
if( bResults )
{
if( dwStatusCode == 304 )
printf( "Document has not been updated.\n" );
else if( dwStatusCode == 200 )
printf( "Document has been updated.\n" );
else
printf( "Status code = %u.\n",dwStatusCode );
}

// Report any errors.
if( !bResults )
printf( "Error %d has occurred.\n", GetLastError( ) );

// Close any open handles.
if( hRequest ) WinHttpCloseHandle( hRequest );
if( hConnect ) WinHttpCloseHandle( hConnect );
if( hSession ) WinHttpCloseHandle( hSession );

Hope This Helps!. Need a simple Code let me know.

Thanks!
Murugan Andezuthu Dharmaratnam

www.muruganad.net

"Nothing Is Impossible, Its Just Improbable"
Post by John Simmons
I'm writing a specialized FTP client that basically synchronizes files
between a server and a client. I've tried a number of methods for
retrieving the file date/time stamp from a couple of servers.
One server is my web-hosting site (referred to as the "remote server"
from this point), and the other is a local FileZilla server running on
Win2K (referred to as "local server" from this point).
The remote server returns the correct date, but the time is always
midnight, no matter what file I choose.
The local server returns what appears to be the file date/time based on
GMT.
When I connect to EITHER server with another FTP client, the file
date/time stamps are displayed normally (the times are what I would
expect).
What should I be doing to retrieve the date/time stamp?
John Simmons
2005-04-18 09:36:37 UTC
Permalink
Post by Murugan Andezuthu Dharmaratnam
Hi John Simon,
I have done something similar to check if file is downloadeble by parts
using WinHTTP , Was writing this for a Distributed HTTP/FTP File Downloader
, Its similar to WinInet . I find the size of the file by adding an
additional header and using WinHttpQueryHeaders() Here is attached sample
code from MSDN.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winhttp/http/winhttpaddrequestheaders.asp
DWORD dwSize = sizeof(DWORD);
DWORD dwStatusCode = 0;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
// Use WinHttpOpen to obtain a session handle.
hSession = WinHttpOpen( L"A WinHTTP Example Program/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS,
0 );
// Specify an HTTP server.
if( hSession )
hConnect = WinHttpConnect( hSession,
L"www.microsoft.com",
INTERNET_DEFAULT_HTTP_PORT,
0 );
// Create an HTTP Request handle.
if( hConnect )
hRequest = WinHttpOpenRequest( hConnect,
L"GET",
NULL,
NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
0 );
// Add a request header.
if( hRequest )
bResults = WinHttpAddRequestHeaders( hRequest,
L"If-Modified-Since: Mon, 20 Nov 2000 20:00:00 GMT",
-1,
WINHTTP_ADDREQ_FLAG_ADD );
// Send a Request.
if( bResults )
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
WINHTTP_NO_REQUEST_DATA,
0,
0,
0 );
// End the request.
if( bResults )
bResults = WinHttpReceiveResponse( hRequest, NULL);
// Use WinHttpQueryHeaders to obtain the header buffer.
if( bResults )
bResults = WinHttpQueryHeaders( hRequest,
WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
NULL,
&dwStatusCode,
&dwSize,
WINHTTP_NO_HEADER_INDEX );
// Based on the status code, determine whether the document was recently
updated.
if( bResults )
{
if( dwStatusCode == 304 )
printf( "Document has not been updated.\n" );
else if( dwStatusCode == 200 )
printf( "Document has been updated.\n" );
else
printf( "Status code = %u.\n",dwStatusCode );
}
// Report any errors.
if( !bResults )
printf( "Error %d has occurred.\n", GetLastError( ) );
// Close any open handles.
if( hRequest ) WinHttpCloseHandle( hRequest );
if( hConnect ) WinHttpCloseHandle( hConnect );
if( hSession ) WinHttpCloseHandle( hSession );
Hope This Helps!. Need a simple Code let me know.
Thanks!
Murugan Andezuthu Dharmaratnam
www.muruganad.net
"Nothing Is Impossible, Its Just Improbable"
Thanks - I'll look into this.
Continue reading on narkive:
Loading...