2 * WININET - Ftp implementation
4 * Copyright 1999 Corel Corporation
5 * Copyright 2004 Mike McCormack for CodeWeavers
6 * Copyright 2004 Kevin Koltzau
7 * Copyright 2007 Hans Leidekker
12 * Copyright 2000 Andreas Mohr
13 * Copyright 2002 Jaco Greeff
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
50 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
55 #define RESPONSE_TIMEOUT 30
57 typedef struct _ftp_session_t ftp_session_t
;
62 ftp_session_t
*lpFtpSession
;
66 HANDLE cache_file_handle
;
75 int pasvSocket
; /* data socket connected by us in case of passive FTP */
76 ftp_file_t
*download_in_progress
;
77 struct sockaddr_in socketAddress
;
78 struct sockaddr_in lstnSocketAddress
;
80 INTERNET_PORT serverport
;
90 SYSTEMTIME tmLastModified
;
91 unsigned short permissions
;
92 } FILEPROPERTIESW
, *LPFILEPROPERTIESW
;
97 ftp_session_t
*lpFtpSession
;
100 LPFILEPROPERTIESW lpafp
;
101 } WININETFTPFINDNEXTW
, *LPWININETFTPFINDNEXTW
;
103 #define DATA_PACKET_SIZE 0x2000
104 #define szCRLF "\r\n"
105 #define MAX_BACKLOG 5
107 /* Testing shows that Windows only accepts dwFlags where the last
108 * 3 (yes 3) bits define FTP_TRANSFER_TYPE_UNKNOWN, FTP_TRANSFER_TYPE_ASCII or FTP_TRANSFER_TYPE_BINARY.
110 #define FTP_CONDITION_MASK 0x0007
113 /* FTP commands with arguments. */
129 /* FTP commands without arguments. */
138 static const CHAR
*const szFtpCommands
[] = {
161 static const CHAR szMonths
[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
162 static const WCHAR szNoAccount
[] = {'n','o','a','c','c','o','u','n','t','\0'};
164 static BOOL
FTP_SendCommand(INT nSocket
, FTP_COMMAND ftpCmd
, LPCWSTR lpszParam
,
165 INTERNET_STATUS_CALLBACK lpfnStatusCB
, object_header_t
*hdr
, DWORD_PTR dwContext
);
166 static BOOL
FTP_SendStore(ftp_session_t
*, LPCWSTR lpszRemoteFile
, DWORD dwType
);
167 static BOOL
FTP_GetDataSocket(ftp_session_t
*, LPINT nDataSocket
);
168 static BOOL
FTP_SendData(ftp_session_t
*, INT nDataSocket
, HANDLE hFile
);
169 static INT
FTP_ReceiveResponse(ftp_session_t
*, DWORD_PTR dwContext
);
170 static BOOL
FTP_SendRetrieve(ftp_session_t
*, LPCWSTR lpszRemoteFile
, DWORD dwType
);
171 static BOOL
FTP_RetrieveFileData(ftp_session_t
*, INT nDataSocket
, HANDLE hFile
);
172 static BOOL
FTP_InitListenSocket(ftp_session_t
*);
173 static BOOL
FTP_ConnectToHost(ftp_session_t
*);
174 static BOOL
FTP_SendPassword(ftp_session_t
*);
175 static BOOL
FTP_SendAccount(ftp_session_t
*);
176 static BOOL
FTP_SendType(ftp_session_t
*, DWORD dwType
);
177 static BOOL
FTP_SendPort(ftp_session_t
*);
178 static BOOL
FTP_DoPassive(ftp_session_t
*);
179 static BOOL
FTP_SendPortOrPasv(ftp_session_t
*);
180 static BOOL
FTP_ParsePermission(LPCSTR lpszPermission
, LPFILEPROPERTIESW lpfp
);
181 static BOOL
FTP_ParseNextFile(INT nSocket
, LPCWSTR lpszSearchFile
, LPFILEPROPERTIESW fileprop
);
182 static BOOL
FTP_ParseDirectory(ftp_session_t
*, INT nSocket
, LPCWSTR lpszSearchFile
,
183 LPFILEPROPERTIESW
*lpafp
, LPDWORD dwfp
);
184 static HINTERNET
FTP_ReceiveFileList(ftp_session_t
*, INT nSocket
, LPCWSTR lpszSearchFile
,
185 LPWIN32_FIND_DATAW lpFindFileData
, DWORD_PTR dwContext
);
186 static DWORD
FTP_SetResponseError(DWORD dwResponse
);
187 static BOOL
FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp
, LPWIN32_FIND_DATAW lpFindFileData
);
188 static BOOL
FTP_FtpPutFileW(ftp_session_t
*, LPCWSTR lpszLocalFile
,
189 LPCWSTR lpszNewRemoteFile
, DWORD dwFlags
, DWORD_PTR dwContext
);
190 static BOOL
FTP_FtpSetCurrentDirectoryW(ftp_session_t
*, LPCWSTR lpszDirectory
);
191 static BOOL
FTP_FtpCreateDirectoryW(ftp_session_t
*, LPCWSTR lpszDirectory
);
192 static HINTERNET
FTP_FtpFindFirstFileW(ftp_session_t
*,
193 LPCWSTR lpszSearchFile
, LPWIN32_FIND_DATAW lpFindFileData
, DWORD dwFlags
, DWORD_PTR dwContext
);
194 static BOOL
FTP_FtpGetCurrentDirectoryW(ftp_session_t
*, LPWSTR lpszCurrentDirectory
,
195 LPDWORD lpdwCurrentDirectory
);
196 static BOOL
FTP_FtpRenameFileW(ftp_session_t
*, LPCWSTR lpszSrc
, LPCWSTR lpszDest
);
197 static BOOL
FTP_FtpRemoveDirectoryW(ftp_session_t
*, LPCWSTR lpszDirectory
);
198 static BOOL
FTP_FtpDeleteFileW(ftp_session_t
*, LPCWSTR lpszFileName
);
199 static BOOL
FTP_FtpGetFileW(ftp_session_t
*, LPCWSTR lpszRemoteFile
, LPCWSTR lpszNewFile
,
200 BOOL fFailIfExists
, DWORD dwLocalFlagsAttribute
, DWORD dwInternetFlags
,
201 DWORD_PTR dwContext
);
203 /* A temporary helper until we get rid of INTERNET_GetLastError calls */
204 static BOOL
res_to_le(DWORD res
)
206 if(res
!= ERROR_SUCCESS
)
207 INTERNET_SetLastError(res
);
208 return res
== ERROR_SUCCESS
;
211 /***********************************************************************
212 * FtpPutFileA (WININET.@)
214 * Uploads a file to the FTP server
221 BOOL WINAPI
FtpPutFileA(HINTERNET hConnect
, LPCSTR lpszLocalFile
,
222 LPCSTR lpszNewRemoteFile
, DWORD dwFlags
, DWORD_PTR dwContext
)
224 LPWSTR lpwzLocalFile
;
225 LPWSTR lpwzNewRemoteFile
;
228 lpwzLocalFile
= heap_strdupAtoW(lpszLocalFile
);
229 lpwzNewRemoteFile
= heap_strdupAtoW(lpszNewRemoteFile
);
230 ret
= FtpPutFileW(hConnect
, lpwzLocalFile
, lpwzNewRemoteFile
,
232 heap_free(lpwzLocalFile
);
233 heap_free(lpwzNewRemoteFile
);
245 static void AsyncFtpPutFileProc(task_header_t
*hdr
)
247 put_file_task_t
*task
= (put_file_task_t
*)hdr
;
248 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
250 TRACE("%p\n", session
);
252 FTP_FtpPutFileW(session
, task
->local_file
, task
->remote_file
,
253 task
->flags
, task
->context
);
255 heap_free(task
->local_file
);
256 heap_free(task
->remote_file
);
259 /***********************************************************************
260 * FtpPutFileW (WININET.@)
262 * Uploads a file to the FTP server
269 BOOL WINAPI
FtpPutFileW(HINTERNET hConnect
, LPCWSTR lpszLocalFile
,
270 LPCWSTR lpszNewRemoteFile
, DWORD dwFlags
, DWORD_PTR dwContext
)
272 ftp_session_t
*lpwfs
;
273 appinfo_t
*hIC
= NULL
;
276 if (!lpszLocalFile
|| !lpszNewRemoteFile
)
278 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
282 lpwfs
= (ftp_session_t
*) get_handle_object( hConnect
);
285 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
289 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
291 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
295 if (lpwfs
->download_in_progress
!= NULL
)
297 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
301 if ((dwFlags
& FTP_CONDITION_MASK
) > FTP_TRANSFER_TYPE_BINARY
)
303 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
307 hIC
= lpwfs
->lpAppInfo
;
308 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
310 put_file_task_t
*task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpPutFileProc
, sizeof(*task
));
312 task
->local_file
= heap_strdupW(lpszLocalFile
);
313 task
->remote_file
= heap_strdupW(lpszNewRemoteFile
);
314 task
->flags
= dwFlags
;
315 task
->context
= dwContext
;
317 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
321 r
= FTP_FtpPutFileW(lpwfs
, lpszLocalFile
,
322 lpszNewRemoteFile
, dwFlags
, dwContext
);
326 WININET_Release( &lpwfs
->hdr
);
331 /***********************************************************************
332 * FTP_FtpPutFileW (Internal)
334 * Uploads a file to the FTP server
341 static BOOL
FTP_FtpPutFileW(ftp_session_t
*lpwfs
, LPCWSTR lpszLocalFile
,
342 LPCWSTR lpszNewRemoteFile
, DWORD dwFlags
, DWORD_PTR dwContext
)
345 BOOL bSuccess
= FALSE
;
346 appinfo_t
*hIC
= NULL
;
349 TRACE(" lpszLocalFile(%s) lpszNewRemoteFile(%s)\n", debugstr_w(lpszLocalFile
), debugstr_w(lpszNewRemoteFile
));
351 /* Clear any error information */
352 INTERNET_SetLastError(0);
354 /* Open file to be uploaded */
355 if (INVALID_HANDLE_VALUE
==
356 (hFile
= CreateFileW(lpszLocalFile
, GENERIC_READ
, 0, 0, OPEN_EXISTING
, 0, 0)))
357 /* Let CreateFile set the appropriate error */
360 hIC
= lpwfs
->lpAppInfo
;
362 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_SENDING_REQUEST
, NULL
, 0);
364 if (FTP_SendStore(lpwfs
, lpszNewRemoteFile
, dwFlags
))
368 /* Get data socket to server */
369 if (FTP_GetDataSocket(lpwfs
, &nDataSocket
))
371 FTP_SendData(lpwfs
, nDataSocket
, hFile
);
372 closesocket(nDataSocket
);
373 nResCode
= FTP_ReceiveResponse(lpwfs
, dwContext
);
379 FTP_SetResponseError(nResCode
);
384 if (lpwfs
->lstnSocket
!= -1)
386 closesocket(lpwfs
->lstnSocket
);
387 lpwfs
->lstnSocket
= -1;
390 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
392 INTERNET_ASYNC_RESULT iar
;
394 iar
.dwResult
= (DWORD
)bSuccess
;
395 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
396 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
397 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
406 /***********************************************************************
407 * FtpSetCurrentDirectoryA (WININET.@)
409 * Change the working directory on the FTP server
416 BOOL WINAPI
FtpSetCurrentDirectoryA(HINTERNET hConnect
, LPCSTR lpszDirectory
)
418 LPWSTR lpwzDirectory
;
421 lpwzDirectory
= heap_strdupAtoW(lpszDirectory
);
422 ret
= FtpSetCurrentDirectoryW(hConnect
, lpwzDirectory
);
423 heap_free(lpwzDirectory
);
432 static void AsyncFtpSetCurrentDirectoryProc(task_header_t
*hdr
)
434 directory_task_t
*task
= (directory_task_t
*)hdr
;
435 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
437 TRACE("%p\n", session
);
439 FTP_FtpSetCurrentDirectoryW(session
, task
->directory
);
440 heap_free(task
->directory
);
443 /***********************************************************************
444 * FtpSetCurrentDirectoryW (WININET.@)
446 * Change the working directory on the FTP server
453 BOOL WINAPI
FtpSetCurrentDirectoryW(HINTERNET hConnect
, LPCWSTR lpszDirectory
)
455 ftp_session_t
*lpwfs
= NULL
;
456 appinfo_t
*hIC
= NULL
;
461 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
465 lpwfs
= (ftp_session_t
*) get_handle_object( hConnect
);
466 if (NULL
== lpwfs
|| WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
468 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
472 if (lpwfs
->download_in_progress
!= NULL
)
474 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
478 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory
));
480 hIC
= lpwfs
->lpAppInfo
;
481 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
483 directory_task_t
*task
;
485 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpSetCurrentDirectoryProc
, sizeof(*task
));
486 task
->directory
= heap_strdupW(lpszDirectory
);
488 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
492 r
= FTP_FtpSetCurrentDirectoryW(lpwfs
, lpszDirectory
);
497 WININET_Release( &lpwfs
->hdr
);
503 /***********************************************************************
504 * FTP_FtpSetCurrentDirectoryW (Internal)
506 * Change the working directory on the FTP server
513 static BOOL
FTP_FtpSetCurrentDirectoryW(ftp_session_t
*lpwfs
, LPCWSTR lpszDirectory
)
516 appinfo_t
*hIC
= NULL
;
517 BOOL bSuccess
= FALSE
;
519 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory
));
521 /* Clear any error information */
522 INTERNET_SetLastError(0);
524 hIC
= lpwfs
->lpAppInfo
;
525 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_CWD
, lpszDirectory
,
526 lpwfs
->hdr
.lpfnStatusCB
, &lpwfs
->hdr
, lpwfs
->hdr
.dwContext
))
529 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
536 FTP_SetResponseError(nResCode
);
540 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
542 INTERNET_ASYNC_RESULT iar
;
544 iar
.dwResult
= bSuccess
;
545 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: ERROR_INTERNET_EXTENDED_ERROR
;
546 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
547 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
553 /***********************************************************************
554 * FtpCreateDirectoryA (WININET.@)
556 * Create new directory on the FTP server
563 BOOL WINAPI
FtpCreateDirectoryA(HINTERNET hConnect
, LPCSTR lpszDirectory
)
565 LPWSTR lpwzDirectory
;
568 lpwzDirectory
= heap_strdupAtoW(lpszDirectory
);
569 ret
= FtpCreateDirectoryW(hConnect
, lpwzDirectory
);
570 heap_free(lpwzDirectory
);
575 static void AsyncFtpCreateDirectoryProc(task_header_t
*hdr
)
577 directory_task_t
*task
= (directory_task_t
*)hdr
;
578 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
580 TRACE(" %p\n", session
);
582 FTP_FtpCreateDirectoryW(session
, task
->directory
);
583 heap_free(task
->directory
);
586 /***********************************************************************
587 * FtpCreateDirectoryW (WININET.@)
589 * Create new directory on the FTP server
596 BOOL WINAPI
FtpCreateDirectoryW(HINTERNET hConnect
, LPCWSTR lpszDirectory
)
598 ftp_session_t
*lpwfs
;
599 appinfo_t
*hIC
= NULL
;
602 lpwfs
= (ftp_session_t
*) get_handle_object( hConnect
);
605 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
609 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
611 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
615 if (lpwfs
->download_in_progress
!= NULL
)
617 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
623 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
627 hIC
= lpwfs
->lpAppInfo
;
628 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
630 directory_task_t
*task
;
632 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpCreateDirectoryProc
, sizeof(*task
));
633 task
->directory
= heap_strdupW(lpszDirectory
);
635 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
639 r
= FTP_FtpCreateDirectoryW(lpwfs
, lpszDirectory
);
642 WININET_Release( &lpwfs
->hdr
);
648 /***********************************************************************
649 * FTP_FtpCreateDirectoryW (Internal)
651 * Create new directory on the FTP server
658 static BOOL
FTP_FtpCreateDirectoryW(ftp_session_t
*lpwfs
, LPCWSTR lpszDirectory
)
661 BOOL bSuccess
= FALSE
;
662 appinfo_t
*hIC
= NULL
;
664 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory
));
666 /* Clear any error information */
667 INTERNET_SetLastError(0);
669 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_MKD
, lpszDirectory
, 0, 0, 0))
672 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
678 FTP_SetResponseError(nResCode
);
682 hIC
= lpwfs
->lpAppInfo
;
683 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
685 INTERNET_ASYNC_RESULT iar
;
687 iar
.dwResult
= (DWORD
)bSuccess
;
688 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
689 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
690 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
696 /***********************************************************************
697 * FtpFindFirstFileA (WININET.@)
699 * Search the specified directory
702 * HINTERNET on success
706 HINTERNET WINAPI
FtpFindFirstFileA(HINTERNET hConnect
,
707 LPCSTR lpszSearchFile
, LPWIN32_FIND_DATAA lpFindFileData
, DWORD dwFlags
, DWORD_PTR dwContext
)
709 LPWSTR lpwzSearchFile
;
710 WIN32_FIND_DATAW wfd
;
711 LPWIN32_FIND_DATAW lpFindFileDataW
;
714 lpwzSearchFile
= heap_strdupAtoW(lpszSearchFile
);
715 lpFindFileDataW
= lpFindFileData
?&wfd
:NULL
;
716 ret
= FtpFindFirstFileW(hConnect
, lpwzSearchFile
, lpFindFileDataW
, dwFlags
, dwContext
);
717 heap_free(lpwzSearchFile
);
719 if (ret
&& lpFindFileData
)
720 WININET_find_data_WtoA(lpFindFileDataW
, lpFindFileData
);
728 WIN32_FIND_DATAW
*find_file_data
;
731 } find_first_file_task_t
;
733 static void AsyncFtpFindFirstFileProc(task_header_t
*hdr
)
735 find_first_file_task_t
*task
= (find_first_file_task_t
*)hdr
;
736 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
738 TRACE("%p\n", session
);
740 FTP_FtpFindFirstFileW(session
, task
->search_file
, task
->find_file_data
, task
->flags
, task
->context
);
741 heap_free(task
->search_file
);
744 /***********************************************************************
745 * FtpFindFirstFileW (WININET.@)
747 * Search the specified directory
750 * HINTERNET on success
754 HINTERNET WINAPI
FtpFindFirstFileW(HINTERNET hConnect
,
755 LPCWSTR lpszSearchFile
, LPWIN32_FIND_DATAW lpFindFileData
, DWORD dwFlags
, DWORD_PTR dwContext
)
757 ftp_session_t
*lpwfs
;
758 appinfo_t
*hIC
= NULL
;
761 lpwfs
= (ftp_session_t
*) get_handle_object( hConnect
);
762 if (NULL
== lpwfs
|| WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
764 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
768 if (lpwfs
->download_in_progress
!= NULL
)
770 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
774 hIC
= lpwfs
->lpAppInfo
;
775 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
777 find_first_file_task_t
*task
;
779 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpFindFirstFileProc
, sizeof(*task
));
780 task
->search_file
= heap_strdupW(lpszSearchFile
);
781 task
->find_file_data
= lpFindFileData
;
782 task
->flags
= dwFlags
;
783 task
->context
= dwContext
;
785 INTERNET_AsyncCall(&task
->hdr
);
790 r
= FTP_FtpFindFirstFileW(lpwfs
, lpszSearchFile
, lpFindFileData
,
795 WININET_Release( &lpwfs
->hdr
);
801 /***********************************************************************
802 * FTP_FtpFindFirstFileW (Internal)
804 * Search the specified directory
807 * HINTERNET on success
811 static HINTERNET
FTP_FtpFindFirstFileW(ftp_session_t
*lpwfs
,
812 LPCWSTR lpszSearchFile
, LPWIN32_FIND_DATAW lpFindFileData
, DWORD dwFlags
, DWORD_PTR dwContext
)
815 appinfo_t
*hIC
= NULL
;
816 HINTERNET hFindNext
= NULL
;
817 LPWSTR lpszSearchPath
= NULL
;
821 /* Clear any error information */
822 INTERNET_SetLastError(0);
824 if (!FTP_InitListenSocket(lpwfs
))
827 if (!FTP_SendType(lpwfs
, INTERNET_FLAG_TRANSFER_ASCII
))
830 if (!FTP_SendPortOrPasv(lpwfs
))
833 /* split search path into file and path */
836 LPCWSTR name
= lpszSearchFile
, p
;
837 if ((p
= strrchrW( name
, '\\' ))) name
= p
+ 1;
838 if ((p
= strrchrW( name
, '/' ))) name
= p
+ 1;
839 if (name
!= lpszSearchFile
)
841 lpszSearchPath
= heap_strndupW(lpszSearchFile
, name
- lpszSearchFile
);
842 lpszSearchFile
= name
;
846 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_LIST
, lpszSearchPath
,
847 lpwfs
->hdr
.lpfnStatusCB
, &lpwfs
->hdr
, lpwfs
->hdr
.dwContext
))
850 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
853 if (nResCode
== 125 || nResCode
== 150)
857 /* Get data socket to server */
858 if (FTP_GetDataSocket(lpwfs
, &nDataSocket
))
860 hFindNext
= FTP_ReceiveFileList(lpwfs
, nDataSocket
, lpszSearchFile
, lpFindFileData
, dwContext
);
861 closesocket(nDataSocket
);
862 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
863 if (nResCode
!= 226 && nResCode
!= 250)
864 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
868 FTP_SetResponseError(nResCode
);
872 heap_free(lpszSearchPath
);
874 if (lpwfs
->lstnSocket
!= -1)
876 closesocket(lpwfs
->lstnSocket
);
877 lpwfs
->lstnSocket
= -1;
880 hIC
= lpwfs
->lpAppInfo
;
881 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
883 INTERNET_ASYNC_RESULT iar
;
887 iar
.dwResult
= (DWORD_PTR
)hFindNext
;
888 iar
.dwError
= ERROR_SUCCESS
;
889 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_HANDLE_CREATED
,
890 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
893 iar
.dwResult
= (DWORD_PTR
)hFindNext
;
894 iar
.dwError
= hFindNext
? ERROR_SUCCESS
: INTERNET_GetLastError();
895 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
896 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
903 /***********************************************************************
904 * FtpGetCurrentDirectoryA (WININET.@)
906 * Retrieves the current directory
913 BOOL WINAPI
FtpGetCurrentDirectoryA(HINTERNET hFtpSession
, LPSTR lpszCurrentDirectory
,
914 LPDWORD lpdwCurrentDirectory
)
920 if(lpdwCurrentDirectory
) {
921 len
= *lpdwCurrentDirectory
;
922 if(lpszCurrentDirectory
)
924 dir
= heap_alloc(len
* sizeof(WCHAR
));
927 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
932 ret
= FtpGetCurrentDirectoryW(hFtpSession
, lpszCurrentDirectory
?dir
:NULL
, lpdwCurrentDirectory
?&len
:NULL
);
934 if (ret
&& lpszCurrentDirectory
)
935 WideCharToMultiByte(CP_ACP
, 0, dir
, -1, lpszCurrentDirectory
, len
, NULL
, NULL
);
937 if (lpdwCurrentDirectory
) *lpdwCurrentDirectory
= len
;
945 DWORD
*directory_len
;
946 } get_current_dir_task_t
;
948 static void AsyncFtpGetCurrentDirectoryProc(task_header_t
*hdr
)
950 get_current_dir_task_t
*task
= (get_current_dir_task_t
*)hdr
;
951 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
953 TRACE("%p\n", session
);
955 FTP_FtpGetCurrentDirectoryW(session
, task
->directory
, task
->directory_len
);
958 /***********************************************************************
959 * FtpGetCurrentDirectoryW (WININET.@)
961 * Retrieves the current directory
968 BOOL WINAPI
FtpGetCurrentDirectoryW(HINTERNET hFtpSession
, LPWSTR lpszCurrentDirectory
,
969 LPDWORD lpdwCurrentDirectory
)
971 ftp_session_t
*lpwfs
;
972 appinfo_t
*hIC
= NULL
;
975 TRACE("%p %p %p\n", hFtpSession
, lpszCurrentDirectory
, lpdwCurrentDirectory
);
977 lpwfs
= (ftp_session_t
*) get_handle_object( hFtpSession
);
980 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
984 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
986 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
990 if (!lpdwCurrentDirectory
)
992 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
996 if (lpszCurrentDirectory
== NULL
)
998 INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1002 if (lpwfs
->download_in_progress
!= NULL
)
1004 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
1008 hIC
= lpwfs
->lpAppInfo
;
1009 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1011 get_current_dir_task_t
*task
;
1013 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpGetCurrentDirectoryProc
, sizeof(*task
));
1014 task
->directory
= lpszCurrentDirectory
;
1015 task
->directory_len
= lpdwCurrentDirectory
;
1017 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
1021 r
= FTP_FtpGetCurrentDirectoryW(lpwfs
, lpszCurrentDirectory
,
1022 lpdwCurrentDirectory
);
1027 WININET_Release( &lpwfs
->hdr
);
1033 /***********************************************************************
1034 * FTP_FtpGetCurrentDirectoryW (Internal)
1036 * Retrieves the current directory
1043 static BOOL
FTP_FtpGetCurrentDirectoryW(ftp_session_t
*lpwfs
, LPWSTR lpszCurrentDirectory
,
1044 LPDWORD lpdwCurrentDirectory
)
1047 appinfo_t
*hIC
= NULL
;
1048 BOOL bSuccess
= FALSE
;
1050 /* Clear any error information */
1051 INTERNET_SetLastError(0);
1053 hIC
= lpwfs
->lpAppInfo
;
1054 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_PWD
, NULL
,
1055 lpwfs
->hdr
.lpfnStatusCB
, &lpwfs
->hdr
, lpwfs
->hdr
.dwContext
))
1058 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
1061 if (nResCode
== 257) /* Extract directory name */
1063 DWORD firstpos
, lastpos
, len
;
1064 LPWSTR lpszResponseBuffer
= heap_strdupAtoW(INTERNET_GetResponseBuffer());
1066 for (firstpos
= 0, lastpos
= 0; lpszResponseBuffer
[lastpos
]; lastpos
++)
1068 if ('"' == lpszResponseBuffer
[lastpos
])
1076 len
= lastpos
- firstpos
;
1077 if (*lpdwCurrentDirectory
>= len
)
1079 memcpy(lpszCurrentDirectory
, &lpszResponseBuffer
[firstpos
+ 1], len
* sizeof(WCHAR
));
1080 lpszCurrentDirectory
[len
- 1] = 0;
1081 *lpdwCurrentDirectory
= len
;
1084 else INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER
);
1086 heap_free(lpszResponseBuffer
);
1089 FTP_SetResponseError(nResCode
);
1093 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1095 INTERNET_ASYNC_RESULT iar
;
1097 iar
.dwResult
= bSuccess
;
1098 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: ERROR_INTERNET_EXTENDED_ERROR
;
1099 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
1100 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
1107 /***********************************************************************
1108 * FTPFILE_Destroy(internal)
1110 * Closes the file transfer handle. This also 'cleans' the data queue of
1111 * the 'transfer complete' message (this is a bit of a hack though :-/ )
1114 static void FTPFILE_Destroy(object_header_t
*hdr
)
1116 ftp_file_t
*lpwh
= (ftp_file_t
*) hdr
;
1117 ftp_session_t
*lpwfs
= lpwh
->lpFtpSession
;
1122 if (lpwh
->cache_file_handle
!= INVALID_HANDLE_VALUE
)
1123 CloseHandle(lpwh
->cache_file_handle
);
1125 heap_free(lpwh
->cache_file
);
1127 if (!lpwh
->session_deleted
)
1128 lpwfs
->download_in_progress
= NULL
;
1130 if (lpwh
->nDataSocket
!= -1)
1131 closesocket(lpwh
->nDataSocket
);
1133 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
1134 if (nResCode
> 0 && nResCode
!= 226) WARN("server reports failed transfer\n");
1136 WININET_Release(&lpwh
->lpFtpSession
->hdr
);
1139 static DWORD
FTPFILE_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
1142 case INTERNET_OPTION_HANDLE_TYPE
:
1143 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
1145 if (*size
< sizeof(ULONG
))
1146 return ERROR_INSUFFICIENT_BUFFER
;
1148 *size
= sizeof(DWORD
);
1149 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_FTP_FILE
;
1150 return ERROR_SUCCESS
;
1151 case INTERNET_OPTION_DATAFILE_NAME
:
1154 ftp_file_t
*file
= (ftp_file_t
*)hdr
;
1156 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
1158 if (!file
->cache_file
)
1161 return ERROR_INTERNET_ITEM_NOT_FOUND
;
1165 required
= (lstrlenW(file
->cache_file
) + 1) * sizeof(WCHAR
);
1166 if (*size
< required
)
1167 return ERROR_INSUFFICIENT_BUFFER
;
1170 memcpy(buffer
, file
->cache_file
, *size
);
1171 return ERROR_SUCCESS
;
1175 required
= WideCharToMultiByte(CP_ACP
, 0, file
->cache_file
, -1, NULL
, 0, NULL
, NULL
);
1176 if (required
> *size
)
1177 return ERROR_INSUFFICIENT_BUFFER
;
1179 *size
= WideCharToMultiByte(CP_ACP
, 0, file
->cache_file
, -1, buffer
, *size
, NULL
, NULL
);
1180 return ERROR_SUCCESS
;
1184 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
1187 static DWORD
FTPFILE_ReadFile(object_header_t
*hdr
, void *buffer
, DWORD size
, DWORD
*read
)
1189 ftp_file_t
*file
= (ftp_file_t
*)hdr
;
1193 if (file
->nDataSocket
== -1)
1194 return ERROR_INTERNET_DISCONNECTED
;
1196 /* FIXME: FTP should use NETCON_ stuff */
1197 res
= sock_recv(file
->nDataSocket
, buffer
, size
, MSG_WAITALL
);
1198 *read
= res
>0 ? res
: 0;
1200 error
= res
>= 0 ? ERROR_SUCCESS
: INTERNET_ERROR_BASE
; /* FIXME */
1201 if (error
== ERROR_SUCCESS
&& file
->cache_file
)
1203 DWORD bytes_written
;
1205 if (!WriteFile(file
->cache_file_handle
, buffer
, *read
, &bytes_written
, NULL
))
1206 WARN("WriteFile failed: %u\n", GetLastError());
1211 static DWORD
FTPFILE_ReadFileEx(object_header_t
*hdr
, void *buf
, DWORD size
, DWORD
*ret_size
,
1212 DWORD flags
, DWORD_PTR context
)
1214 return FTPFILE_ReadFile(hdr
, buf
, size
, ret_size
);
1217 static DWORD
FTPFILE_WriteFile(object_header_t
*hdr
, const void *buffer
, DWORD size
, DWORD
*written
)
1219 ftp_file_t
*lpwh
= (ftp_file_t
*) hdr
;
1222 res
= sock_send(lpwh
->nDataSocket
, buffer
, size
, 0);
1224 *written
= res
>0 ? res
: 0;
1225 return res
>= 0 ? ERROR_SUCCESS
: WSAGetLastError();
1228 static void FTP_ReceiveRequestData(ftp_file_t
*file
, BOOL first_notif
)
1230 INTERNET_ASYNC_RESULT iar
;
1234 TRACE("%p\n", file
);
1236 available
= sock_recv(file
->nDataSocket
, buffer
, sizeof(buffer
), MSG_PEEK
);
1238 if(available
!= -1) {
1239 iar
.dwResult
= (DWORD_PTR
)file
->hdr
.hInternet
;
1240 iar
.dwError
= first_notif
? 0 : available
;
1243 iar
.dwError
= INTERNET_GetLastError();
1246 INTERNET_SendCallback(&file
->hdr
, file
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
1247 sizeof(INTERNET_ASYNC_RESULT
));
1250 static void FTPFILE_AsyncQueryDataAvailableProc(task_header_t
*task
)
1252 ftp_file_t
*file
= (ftp_file_t
*)task
->hdr
;
1254 FTP_ReceiveRequestData(file
, FALSE
);
1257 static DWORD
FTPFILE_QueryDataAvailable(object_header_t
*hdr
, DWORD
*available
, DWORD flags
, DWORD_PTR ctx
)
1259 ftp_file_t
*file
= (ftp_file_t
*) hdr
;
1263 TRACE("(%p %p %x %lx)\n", file
, available
, flags
, ctx
);
1265 retval
= ioctlsocket(file
->nDataSocket
, FIONREAD
, &unread
);
1267 TRACE("%d bytes of queued, but unread data\n", unread
);
1269 *available
= unread
;
1276 retval
= sock_recv(file
->nDataSocket
, &byte
, 1, MSG_PEEK
);
1278 task_header_t
*task
;
1280 task
= alloc_async_task(&file
->hdr
, FTPFILE_AsyncQueryDataAvailableProc
, sizeof(*task
));
1281 INTERNET_AsyncCall(task
);
1283 return ERROR_IO_PENDING
;
1287 return ERROR_SUCCESS
;
1290 static DWORD
FTPFILE_LockRequestFile(object_header_t
*hdr
, req_file_t
**ret
)
1292 ftp_file_t
*file
= (ftp_file_t
*)hdr
;
1293 FIXME("%p\n", file
);
1294 return ERROR_NOT_SUPPORTED
;
1297 static const object_vtbl_t FTPFILEVtbl
= {
1300 FTPFILE_QueryOption
,
1305 FTPFILE_QueryDataAvailable
,
1307 FTPFILE_LockRequestFile
1310 /***********************************************************************
1311 * FTP_FtpOpenFileW (Internal)
1313 * Open a remote file for writing or reading
1316 * HINTERNET handle on success
1320 static HINTERNET
FTP_FtpOpenFileW(ftp_session_t
*lpwfs
,
1321 LPCWSTR lpszFileName
, DWORD fdwAccess
, DWORD dwFlags
,
1322 DWORD_PTR dwContext
)
1325 BOOL bSuccess
= FALSE
;
1326 ftp_file_t
*lpwh
= NULL
;
1327 appinfo_t
*hIC
= NULL
;
1331 /* Clear any error information */
1332 INTERNET_SetLastError(0);
1334 if (GENERIC_READ
== fdwAccess
)
1336 /* Set up socket to retrieve data */
1337 bSuccess
= FTP_SendRetrieve(lpwfs
, lpszFileName
, dwFlags
);
1339 else if (GENERIC_WRITE
== fdwAccess
)
1341 /* Set up socket to send data */
1342 bSuccess
= FTP_SendStore(lpwfs
, lpszFileName
, dwFlags
);
1345 /* Get data socket to server */
1346 if (bSuccess
&& FTP_GetDataSocket(lpwfs
, &nDataSocket
))
1348 lpwh
= alloc_object(&lpwfs
->hdr
, &FTPFILEVtbl
, sizeof(ftp_file_t
));
1349 lpwh
->hdr
.htype
= WH_HFILE
;
1350 lpwh
->hdr
.dwFlags
= dwFlags
;
1351 lpwh
->hdr
.dwContext
= dwContext
;
1352 lpwh
->nDataSocket
= nDataSocket
;
1353 lpwh
->cache_file
= NULL
;
1354 lpwh
->cache_file_handle
= INVALID_HANDLE_VALUE
;
1355 lpwh
->session_deleted
= FALSE
;
1357 WININET_AddRef( &lpwfs
->hdr
);
1358 lpwh
->lpFtpSession
= lpwfs
;
1359 list_add_head( &lpwfs
->hdr
.children
, &lpwh
->hdr
.entry
);
1361 /* Indicate that a download is currently in progress */
1362 lpwfs
->download_in_progress
= lpwh
;
1365 if (lpwfs
->lstnSocket
!= -1)
1367 closesocket(lpwfs
->lstnSocket
);
1368 lpwfs
->lstnSocket
= -1;
1371 if (bSuccess
&& fdwAccess
== GENERIC_READ
)
1373 WCHAR filename
[MAX_PATH
+ 1];
1377 memset(&uc
, 0, sizeof(uc
));
1378 uc
.dwStructSize
= sizeof(uc
);
1379 uc
.nScheme
= INTERNET_SCHEME_FTP
;
1380 uc
.lpszHostName
= lpwfs
->servername
;
1381 uc
.nPort
= lpwfs
->serverport
;
1382 uc
.lpszUserName
= lpwfs
->lpszUserName
;
1383 uc
.lpszUrlPath
= heap_strdupW(lpszFileName
);
1385 if (!InternetCreateUrlW(&uc
, 0, NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1387 WCHAR
*url
= heap_alloc(len
* sizeof(WCHAR
));
1389 if (url
&& InternetCreateUrlW(&uc
, 0, url
, &len
) && CreateUrlCacheEntryW(url
, 0, NULL
, filename
, 0))
1391 lpwh
->cache_file
= heap_strdupW(filename
);
1392 lpwh
->cache_file_handle
= CreateFileW(filename
, GENERIC_WRITE
, FILE_SHARE_READ
,
1393 NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1394 if (lpwh
->cache_file_handle
== INVALID_HANDLE_VALUE
)
1396 WARN("Could not create cache file: %u\n", GetLastError());
1397 heap_free(lpwh
->cache_file
);
1398 lpwh
->cache_file
= NULL
;
1403 heap_free(uc
.lpszUrlPath
);
1406 hIC
= lpwfs
->lpAppInfo
;
1407 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1409 INTERNET_ASYNC_RESULT iar
;
1413 iar
.dwResult
= (DWORD_PTR
)lpwh
->hdr
.hInternet
;
1414 iar
.dwError
= ERROR_SUCCESS
;
1415 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_HANDLE_CREATED
,
1416 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
1420 FTP_ReceiveRequestData(lpwh
, TRUE
);
1423 iar
.dwError
= INTERNET_GetLastError();
1424 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
1425 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
1432 return lpwh
->hdr
.hInternet
;
1436 /***********************************************************************
1437 * FtpOpenFileA (WININET.@)
1439 * Open a remote file for writing or reading
1442 * HINTERNET handle on success
1446 HINTERNET WINAPI
FtpOpenFileA(HINTERNET hFtpSession
,
1447 LPCSTR lpszFileName
, DWORD fdwAccess
, DWORD dwFlags
,
1448 DWORD_PTR dwContext
)
1450 LPWSTR lpwzFileName
;
1453 lpwzFileName
= heap_strdupAtoW(lpszFileName
);
1454 ret
= FtpOpenFileW(hFtpSession
, lpwzFileName
, fdwAccess
, dwFlags
, dwContext
);
1455 heap_free(lpwzFileName
);
1467 static void AsyncFtpOpenFileProc(task_header_t
*hdr
)
1469 open_file_task_t
*task
= (open_file_task_t
*)hdr
;
1470 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
1472 TRACE("%p\n", session
);
1474 FTP_FtpOpenFileW(session
, task
->file_name
, task
->access
, task
->flags
, task
->context
);
1475 heap_free(task
->file_name
);
1478 /***********************************************************************
1479 * FtpOpenFileW (WININET.@)
1481 * Open a remote file for writing or reading
1484 * HINTERNET handle on success
1488 HINTERNET WINAPI
FtpOpenFileW(HINTERNET hFtpSession
,
1489 LPCWSTR lpszFileName
, DWORD fdwAccess
, DWORD dwFlags
,
1490 DWORD_PTR dwContext
)
1492 ftp_session_t
*lpwfs
;
1493 appinfo_t
*hIC
= NULL
;
1496 TRACE("(%p,%s,0x%08x,0x%08x,0x%08lx)\n", hFtpSession
,
1497 debugstr_w(lpszFileName
), fdwAccess
, dwFlags
, dwContext
);
1499 lpwfs
= (ftp_session_t
*) get_handle_object( hFtpSession
);
1502 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1506 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
1508 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1512 if ((!lpszFileName
) ||
1513 ((fdwAccess
!= GENERIC_READ
) && (fdwAccess
!= GENERIC_WRITE
)) ||
1514 ((dwFlags
& FTP_CONDITION_MASK
) > FTP_TRANSFER_TYPE_BINARY
))
1516 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1520 if (lpwfs
->download_in_progress
!= NULL
)
1522 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
1526 hIC
= lpwfs
->lpAppInfo
;
1527 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1529 open_file_task_t
*task
;
1531 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpOpenFileProc
, sizeof(*task
));
1532 task
->file_name
= heap_strdupW(lpszFileName
);
1533 task
->access
= fdwAccess
;
1534 task
->flags
= dwFlags
;
1535 task
->context
= dwContext
;
1537 INTERNET_AsyncCall(&task
->hdr
);
1542 r
= FTP_FtpOpenFileW(lpwfs
, lpszFileName
, fdwAccess
, dwFlags
, dwContext
);
1546 WININET_Release( &lpwfs
->hdr
);
1552 /***********************************************************************
1553 * FtpGetFileA (WININET.@)
1555 * Retrieve file from the FTP server
1562 BOOL WINAPI
FtpGetFileA(HINTERNET hInternet
, LPCSTR lpszRemoteFile
, LPCSTR lpszNewFile
,
1563 BOOL fFailIfExists
, DWORD dwLocalFlagsAttribute
, DWORD dwInternetFlags
,
1564 DWORD_PTR dwContext
)
1566 LPWSTR lpwzRemoteFile
;
1570 lpwzRemoteFile
= heap_strdupAtoW(lpszRemoteFile
);
1571 lpwzNewFile
= heap_strdupAtoW(lpszNewFile
);
1572 ret
= FtpGetFileW(hInternet
, lpwzRemoteFile
, lpwzNewFile
, fFailIfExists
,
1573 dwLocalFlagsAttribute
, dwInternetFlags
, dwContext
);
1574 heap_free(lpwzRemoteFile
);
1575 heap_free(lpwzNewFile
);
1583 BOOL fail_if_exists
;
1589 static void AsyncFtpGetFileProc(task_header_t
*hdr
)
1591 get_file_task_t
*task
= (get_file_task_t
*)hdr
;
1592 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
1594 TRACE("%p\n", session
);
1596 FTP_FtpGetFileW(session
, task
->remote_file
, task
->new_file
, task
->fail_if_exists
,
1597 task
->local_attr
, task
->flags
, task
->context
);
1598 heap_free(task
->remote_file
);
1599 heap_free(task
->new_file
);
1603 /***********************************************************************
1604 * FtpGetFileW (WININET.@)
1606 * Retrieve file from the FTP server
1613 BOOL WINAPI
FtpGetFileW(HINTERNET hInternet
, LPCWSTR lpszRemoteFile
, LPCWSTR lpszNewFile
,
1614 BOOL fFailIfExists
, DWORD dwLocalFlagsAttribute
, DWORD dwInternetFlags
,
1615 DWORD_PTR dwContext
)
1617 ftp_session_t
*lpwfs
;
1618 appinfo_t
*hIC
= NULL
;
1621 if (!lpszRemoteFile
|| !lpszNewFile
)
1623 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1627 lpwfs
= (ftp_session_t
*) get_handle_object( hInternet
);
1630 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1634 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
1636 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1640 if ((dwInternetFlags
& FTP_CONDITION_MASK
) > FTP_TRANSFER_TYPE_BINARY
)
1642 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1646 if (lpwfs
->download_in_progress
!= NULL
)
1648 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
1652 hIC
= lpwfs
->lpAppInfo
;
1653 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1655 get_file_task_t
*task
;
1657 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpGetFileProc
, sizeof(*task
));
1658 task
->remote_file
= heap_strdupW(lpszRemoteFile
);
1659 task
->new_file
= heap_strdupW(lpszNewFile
);
1660 task
->local_attr
= dwLocalFlagsAttribute
;
1661 task
->fail_if_exists
= fFailIfExists
;
1662 task
->flags
= dwInternetFlags
;
1663 task
->context
= dwContext
;
1665 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
1669 r
= FTP_FtpGetFileW(lpwfs
, lpszRemoteFile
, lpszNewFile
,
1670 fFailIfExists
, dwLocalFlagsAttribute
, dwInternetFlags
, dwContext
);
1674 WININET_Release( &lpwfs
->hdr
);
1680 /***********************************************************************
1681 * FTP_FtpGetFileW (Internal)
1683 * Retrieve file from the FTP server
1690 static BOOL
FTP_FtpGetFileW(ftp_session_t
*lpwfs
, LPCWSTR lpszRemoteFile
, LPCWSTR lpszNewFile
,
1691 BOOL fFailIfExists
, DWORD dwLocalFlagsAttribute
, DWORD dwInternetFlags
,
1692 DWORD_PTR dwContext
)
1694 BOOL bSuccess
= FALSE
;
1696 appinfo_t
*hIC
= NULL
;
1698 TRACE("lpszRemoteFile(%s) lpszNewFile(%s)\n", debugstr_w(lpszRemoteFile
), debugstr_w(lpszNewFile
));
1700 /* Clear any error information */
1701 INTERNET_SetLastError(0);
1703 /* Ensure we can write to lpszNewfile by opening it */
1704 hFile
= CreateFileW(lpszNewFile
, GENERIC_WRITE
, 0, 0, fFailIfExists
?
1705 CREATE_NEW
: CREATE_ALWAYS
, dwLocalFlagsAttribute
, 0);
1706 if (INVALID_HANDLE_VALUE
== hFile
)
1709 /* Set up socket to retrieve data */
1710 if (FTP_SendRetrieve(lpwfs
, lpszRemoteFile
, dwInternetFlags
))
1714 /* Get data socket to server */
1715 if (FTP_GetDataSocket(lpwfs
, &nDataSocket
))
1720 FTP_RetrieveFileData(lpwfs
, nDataSocket
, hFile
);
1721 closesocket(nDataSocket
);
1723 nResCode
= FTP_ReceiveResponse(lpwfs
, dwContext
);
1726 if (nResCode
== 226)
1729 FTP_SetResponseError(nResCode
);
1734 if (lpwfs
->lstnSocket
!= -1)
1736 closesocket(lpwfs
->lstnSocket
);
1737 lpwfs
->lstnSocket
= -1;
1742 hIC
= lpwfs
->lpAppInfo
;
1743 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1745 INTERNET_ASYNC_RESULT iar
;
1747 iar
.dwResult
= (DWORD
)bSuccess
;
1748 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
1749 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
1750 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
1753 if (!bSuccess
) DeleteFileW(lpszNewFile
);
1757 /***********************************************************************
1758 * FtpGetFileSize (WININET.@)
1760 DWORD WINAPI
FtpGetFileSize( HINTERNET hFile
, LPDWORD lpdwFileSizeHigh
)
1762 FIXME("(%p, %p)\n", hFile
, lpdwFileSizeHigh
);
1764 if (lpdwFileSizeHigh
)
1765 *lpdwFileSizeHigh
= 0;
1770 /***********************************************************************
1771 * FtpDeleteFileA (WININET.@)
1773 * Delete a file on the ftp server
1780 BOOL WINAPI
FtpDeleteFileA(HINTERNET hFtpSession
, LPCSTR lpszFileName
)
1782 LPWSTR lpwzFileName
;
1785 lpwzFileName
= heap_strdupAtoW(lpszFileName
);
1786 ret
= FtpDeleteFileW(hFtpSession
, lpwzFileName
);
1787 heap_free(lpwzFileName
);
1794 } delete_file_task_t
;
1796 static void AsyncFtpDeleteFileProc(task_header_t
*hdr
)
1798 delete_file_task_t
*task
= (delete_file_task_t
*)hdr
;
1799 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
1801 TRACE("%p\n", session
);
1803 FTP_FtpDeleteFileW(session
, task
->file_name
);
1804 heap_free(task
->file_name
);
1807 /***********************************************************************
1808 * FtpDeleteFileW (WININET.@)
1810 * Delete a file on the ftp server
1817 BOOL WINAPI
FtpDeleteFileW(HINTERNET hFtpSession
, LPCWSTR lpszFileName
)
1819 ftp_session_t
*lpwfs
;
1820 appinfo_t
*hIC
= NULL
;
1823 lpwfs
= (ftp_session_t
*) get_handle_object( hFtpSession
);
1826 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1830 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
1832 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1836 if (lpwfs
->download_in_progress
!= NULL
)
1838 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
1844 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1848 hIC
= lpwfs
->lpAppInfo
;
1849 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1851 delete_file_task_t
*task
;
1853 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpDeleteFileProc
, sizeof(*task
));
1854 task
->file_name
= heap_strdupW(lpszFileName
);
1856 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
1860 r
= FTP_FtpDeleteFileW(lpwfs
, lpszFileName
);
1864 WININET_Release( &lpwfs
->hdr
);
1869 /***********************************************************************
1870 * FTP_FtpDeleteFileW (Internal)
1872 * Delete a file on the ftp server
1879 BOOL
FTP_FtpDeleteFileW(ftp_session_t
*lpwfs
, LPCWSTR lpszFileName
)
1882 BOOL bSuccess
= FALSE
;
1883 appinfo_t
*hIC
= NULL
;
1885 TRACE("%p\n", lpwfs
);
1887 /* Clear any error information */
1888 INTERNET_SetLastError(0);
1890 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_DELE
, lpszFileName
, 0, 0, 0))
1893 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
1896 if (nResCode
== 250)
1899 FTP_SetResponseError(nResCode
);
1902 hIC
= lpwfs
->lpAppInfo
;
1903 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1905 INTERNET_ASYNC_RESULT iar
;
1907 iar
.dwResult
= (DWORD
)bSuccess
;
1908 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
1909 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
1910 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
1917 /***********************************************************************
1918 * FtpRemoveDirectoryA (WININET.@)
1920 * Remove a directory on the ftp server
1927 BOOL WINAPI
FtpRemoveDirectoryA(HINTERNET hFtpSession
, LPCSTR lpszDirectory
)
1929 LPWSTR lpwzDirectory
;
1932 lpwzDirectory
= heap_strdupAtoW(lpszDirectory
);
1933 ret
= FtpRemoveDirectoryW(hFtpSession
, lpwzDirectory
);
1934 heap_free(lpwzDirectory
);
1938 static void AsyncFtpRemoveDirectoryProc(task_header_t
*hdr
)
1940 directory_task_t
*task
= (directory_task_t
*)hdr
;
1941 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
1943 TRACE("%p\n", session
);
1945 FTP_FtpRemoveDirectoryW(session
, task
->directory
);
1946 heap_free(task
->directory
);
1949 /***********************************************************************
1950 * FtpRemoveDirectoryW (WININET.@)
1952 * Remove a directory on the ftp server
1959 BOOL WINAPI
FtpRemoveDirectoryW(HINTERNET hFtpSession
, LPCWSTR lpszDirectory
)
1961 ftp_session_t
*lpwfs
;
1962 appinfo_t
*hIC
= NULL
;
1965 lpwfs
= (ftp_session_t
*) get_handle_object( hFtpSession
);
1968 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
1972 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
1974 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
1978 if (lpwfs
->download_in_progress
!= NULL
)
1980 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
1986 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
1990 hIC
= lpwfs
->lpAppInfo
;
1991 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
1993 directory_task_t
*task
;
1995 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpRemoveDirectoryProc
, sizeof(*task
));
1996 task
->directory
= heap_strdupW(lpszDirectory
);
1998 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
2002 r
= FTP_FtpRemoveDirectoryW(lpwfs
, lpszDirectory
);
2006 WININET_Release( &lpwfs
->hdr
);
2011 /***********************************************************************
2012 * FTP_FtpRemoveDirectoryW (Internal)
2014 * Remove a directory on the ftp server
2021 BOOL
FTP_FtpRemoveDirectoryW(ftp_session_t
*lpwfs
, LPCWSTR lpszDirectory
)
2024 BOOL bSuccess
= FALSE
;
2025 appinfo_t
*hIC
= NULL
;
2029 /* Clear any error information */
2030 INTERNET_SetLastError(0);
2032 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_RMD
, lpszDirectory
, 0, 0, 0))
2035 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2038 if (nResCode
== 250)
2041 FTP_SetResponseError(nResCode
);
2045 hIC
= lpwfs
->lpAppInfo
;
2046 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
2048 INTERNET_ASYNC_RESULT iar
;
2050 iar
.dwResult
= (DWORD
)bSuccess
;
2051 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
2052 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
2053 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
2060 /***********************************************************************
2061 * FtpRenameFileA (WININET.@)
2063 * Rename a file on the ftp server
2070 BOOL WINAPI
FtpRenameFileA(HINTERNET hFtpSession
, LPCSTR lpszSrc
, LPCSTR lpszDest
)
2076 lpwzSrc
= heap_strdupAtoW(lpszSrc
);
2077 lpwzDest
= heap_strdupAtoW(lpszDest
);
2078 ret
= FtpRenameFileW(hFtpSession
, lpwzSrc
, lpwzDest
);
2080 heap_free(lpwzDest
);
2088 } rename_file_task_t
;
2090 static void AsyncFtpRenameFileProc(task_header_t
*hdr
)
2092 rename_file_task_t
*task
= (rename_file_task_t
*)hdr
;
2093 ftp_session_t
*session
= (ftp_session_t
*)task
->hdr
.hdr
;
2095 TRACE("%p\n", session
);
2097 FTP_FtpRenameFileW(session
, task
->src_file
, task
->dst_file
);
2098 heap_free(task
->src_file
);
2099 heap_free(task
->dst_file
);
2102 /***********************************************************************
2103 * FtpRenameFileW (WININET.@)
2105 * Rename a file on the ftp server
2112 BOOL WINAPI
FtpRenameFileW(HINTERNET hFtpSession
, LPCWSTR lpszSrc
, LPCWSTR lpszDest
)
2114 ftp_session_t
*lpwfs
;
2115 appinfo_t
*hIC
= NULL
;
2118 lpwfs
= (ftp_session_t
*) get_handle_object( hFtpSession
);
2121 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2125 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
2127 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2131 if (lpwfs
->download_in_progress
!= NULL
)
2133 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
2137 if (!lpszSrc
|| !lpszDest
)
2139 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2143 hIC
= lpwfs
->lpAppInfo
;
2144 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
2146 rename_file_task_t
*task
;
2148 task
= alloc_async_task(&lpwfs
->hdr
, AsyncFtpRenameFileProc
, sizeof(*task
));
2149 task
->src_file
= heap_strdupW(lpszSrc
);
2150 task
->dst_file
= heap_strdupW(lpszDest
);
2152 r
= res_to_le(INTERNET_AsyncCall(&task
->hdr
));
2156 r
= FTP_FtpRenameFileW(lpwfs
, lpszSrc
, lpszDest
);
2160 WININET_Release( &lpwfs
->hdr
);
2165 /***********************************************************************
2166 * FTP_FtpRenameFileW (Internal)
2168 * Rename a file on the ftp server
2175 BOOL
FTP_FtpRenameFileW(ftp_session_t
*lpwfs
, LPCWSTR lpszSrc
, LPCWSTR lpszDest
)
2178 BOOL bSuccess
= FALSE
;
2179 appinfo_t
*hIC
= NULL
;
2183 /* Clear any error information */
2184 INTERNET_SetLastError(0);
2186 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_RNFR
, lpszSrc
, 0, 0, 0))
2189 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2190 if (nResCode
== 350)
2192 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_RNTO
, lpszDest
, 0, 0, 0))
2195 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2198 if (nResCode
== 250)
2201 FTP_SetResponseError(nResCode
);
2204 hIC
= lpwfs
->lpAppInfo
;
2205 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
2207 INTERNET_ASYNC_RESULT iar
;
2209 iar
.dwResult
= (DWORD
)bSuccess
;
2210 iar
.dwError
= bSuccess
? ERROR_SUCCESS
: INTERNET_GetLastError();
2211 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
, INTERNET_STATUS_REQUEST_COMPLETE
,
2212 &iar
, sizeof(INTERNET_ASYNC_RESULT
));
2218 /***********************************************************************
2219 * FtpCommandA (WININET.@)
2221 BOOL WINAPI
FtpCommandA( HINTERNET hConnect
, BOOL fExpectResponse
, DWORD dwFlags
,
2222 LPCSTR lpszCommand
, DWORD_PTR dwContext
, HINTERNET
* phFtpCommand
)
2227 TRACE("%p %d 0x%08x %s 0x%08lx %p\n", hConnect
, fExpectResponse
, dwFlags
,
2228 debugstr_a(lpszCommand
), dwContext
, phFtpCommand
);
2230 if (fExpectResponse
)
2232 FIXME("data connection not supported\n");
2236 if (!lpszCommand
|| !lpszCommand
[0])
2238 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2242 if (!(cmdW
= heap_strdupAtoW(lpszCommand
)))
2244 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2248 r
= FtpCommandW(hConnect
, fExpectResponse
, dwFlags
, cmdW
, dwContext
, phFtpCommand
);
2254 /***********************************************************************
2255 * FtpCommandW (WININET.@)
2257 BOOL WINAPI
FtpCommandW( HINTERNET hConnect
, BOOL fExpectResponse
, DWORD dwFlags
,
2258 LPCWSTR lpszCommand
, DWORD_PTR dwContext
, HINTERNET
* phFtpCommand
)
2261 ftp_session_t
*lpwfs
;
2263 DWORD len
, nBytesSent
= 0;
2264 INT nResCode
, nRC
= 0;
2266 TRACE("%p %d 0x%08x %s 0x%08lx %p\n", hConnect
, fExpectResponse
, dwFlags
,
2267 debugstr_w(lpszCommand
), dwContext
, phFtpCommand
);
2269 if (!lpszCommand
|| !lpszCommand
[0])
2271 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2275 if (fExpectResponse
)
2277 FIXME("data connection not supported\n");
2281 lpwfs
= (ftp_session_t
*) get_handle_object( hConnect
);
2284 INTERNET_SetLastError(ERROR_INVALID_HANDLE
);
2288 if (WH_HFTPSESSION
!= lpwfs
->hdr
.htype
)
2290 INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE
);
2294 if (lpwfs
->download_in_progress
!= NULL
)
2296 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
2300 len
= WideCharToMultiByte(CP_ACP
, 0, lpszCommand
, -1, NULL
, 0, NULL
, NULL
) + strlen(szCRLF
);
2301 if ((cmd
= heap_alloc(len
)))
2302 WideCharToMultiByte(CP_ACP
, 0, lpszCommand
, -1, cmd
, len
, NULL
, NULL
);
2305 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2309 strcat(cmd
, szCRLF
);
2312 TRACE("Sending (%s) len(%d)\n", debugstr_a(cmd
), len
);
2313 while ((nBytesSent
< len
) && (nRC
!= -1))
2315 nRC
= sock_send(lpwfs
->sndSocket
, cmd
+ nBytesSent
, len
- nBytesSent
, 0);
2319 TRACE("Sent %d bytes\n", nRC
);
2325 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2326 if (nResCode
> 0 && nResCode
< 400)
2329 FTP_SetResponseError(nResCode
);
2333 WININET_Release( &lpwfs
->hdr
);
2339 /***********************************************************************
2340 * FTPSESSION_Destroy (internal)
2342 * Deallocate session handle
2344 static void FTPSESSION_Destroy(object_header_t
*hdr
)
2346 ftp_session_t
*lpwfs
= (ftp_session_t
*) hdr
;
2350 WININET_Release(&lpwfs
->lpAppInfo
->hdr
);
2352 heap_free(lpwfs
->lpszPassword
);
2353 heap_free(lpwfs
->lpszUserName
);
2354 heap_free(lpwfs
->servername
);
2357 static void FTPSESSION_CloseConnection(object_header_t
*hdr
)
2359 ftp_session_t
*lpwfs
= (ftp_session_t
*) hdr
;
2363 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
,
2364 INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0);
2366 if (lpwfs
->download_in_progress
!= NULL
)
2367 lpwfs
->download_in_progress
->session_deleted
= TRUE
;
2369 if (lpwfs
->sndSocket
!= -1)
2370 closesocket(lpwfs
->sndSocket
);
2372 if (lpwfs
->lstnSocket
!= -1)
2373 closesocket(lpwfs
->lstnSocket
);
2375 if (lpwfs
->pasvSocket
!= -1)
2376 closesocket(lpwfs
->pasvSocket
);
2378 SendAsyncCallback(&lpwfs
->hdr
, lpwfs
->hdr
.dwContext
,
2379 INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0);
2382 static DWORD
FTPSESSION_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
2385 case INTERNET_OPTION_HANDLE_TYPE
:
2386 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
2388 if (*size
< sizeof(ULONG
))
2389 return ERROR_INSUFFICIENT_BUFFER
;
2391 *size
= sizeof(DWORD
);
2392 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_CONNECT_FTP
;
2393 return ERROR_SUCCESS
;
2396 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
2399 static const object_vtbl_t FTPSESSIONVtbl
= {
2401 FTPSESSION_CloseConnection
,
2402 FTPSESSION_QueryOption
,
2412 /***********************************************************************
2413 * FTP_Connect (internal)
2415 * Connect to a ftp server
2418 * HINTERNET a session handle on success
2423 * Windows uses 'anonymous' as the username, when given a NULL username
2424 * and a NULL password. The password is first looked up in:
2426 * HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\EmailName
2428 * If this entry is not present it uses the current username as the password.
2432 HINTERNET
FTP_Connect(appinfo_t
*hIC
, LPCWSTR lpszServerName
,
2433 INTERNET_PORT nServerPort
, LPCWSTR lpszUserName
,
2434 LPCWSTR lpszPassword
, DWORD dwFlags
, DWORD_PTR dwContext
,
2435 DWORD dwInternalFlags
)
2437 static const WCHAR szKey
[] = {'S','o','f','t','w','a','r','e','\\',
2438 'M','i','c','r','o','s','o','f','t','\\',
2439 'W','i','n','d','o','w','s','\\',
2440 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
2441 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
2442 static const WCHAR szValue
[] = {'E','m','a','i','l','N','a','m','e',0};
2443 static const WCHAR szDefaultUsername
[] = {'a','n','o','n','y','m','o','u','s','\0'};
2444 static const WCHAR szEmpty
[] = {'\0'};
2445 struct sockaddr_in socketAddr
;
2447 socklen_t sock_namelen
;
2448 BOOL bSuccess
= FALSE
;
2449 ftp_session_t
*lpwfs
= NULL
;
2450 char szaddr
[INET6_ADDRSTRLEN
];
2452 TRACE("%p Server(%s) Port(%d) User(%s) Paswd(%s)\n",
2453 hIC
, debugstr_w(lpszServerName
),
2454 nServerPort
, debugstr_w(lpszUserName
), debugstr_w(lpszPassword
));
2456 assert( hIC
->hdr
.htype
== WH_HINIT
);
2458 if ((!lpszUserName
|| !*lpszUserName
) && lpszPassword
&& *lpszPassword
)
2460 INTERNET_SetLastError(ERROR_INVALID_PARAMETER
);
2464 lpwfs
= alloc_object(&hIC
->hdr
, &FTPSESSIONVtbl
, sizeof(ftp_session_t
));
2467 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2471 if (nServerPort
== INTERNET_INVALID_PORT_NUMBER
)
2472 lpwfs
->serverport
= INTERNET_DEFAULT_FTP_PORT
;
2474 lpwfs
->serverport
= nServerPort
;
2476 lpwfs
->hdr
.htype
= WH_HFTPSESSION
;
2477 lpwfs
->hdr
.dwFlags
= dwFlags
;
2478 lpwfs
->hdr
.dwContext
= dwContext
;
2479 lpwfs
->hdr
.dwInternalFlags
|= dwInternalFlags
;
2480 lpwfs
->download_in_progress
= NULL
;
2481 lpwfs
->sndSocket
= -1;
2482 lpwfs
->lstnSocket
= -1;
2483 lpwfs
->pasvSocket
= -1;
2485 WININET_AddRef( &hIC
->hdr
);
2486 lpwfs
->lpAppInfo
= hIC
;
2487 list_add_head( &hIC
->hdr
.children
, &lpwfs
->hdr
.entry
);
2489 if(hIC
->proxy
&& hIC
->accessType
== INTERNET_OPEN_TYPE_PROXY
) {
2490 if(strchrW(hIC
->proxy
, ' '))
2491 FIXME("Several proxies not implemented.\n");
2492 if(hIC
->proxyBypass
)
2493 FIXME("Proxy bypass is ignored.\n");
2495 if (!lpszUserName
|| !lpszUserName
[0]) {
2497 WCHAR szPassword
[MAX_PATH
];
2498 DWORD len
= sizeof(szPassword
);
2500 lpwfs
->lpszUserName
= heap_strdupW(szDefaultUsername
);
2502 RegOpenKeyW(HKEY_CURRENT_USER
, szKey
, &key
);
2503 if (RegQueryValueExW(key
, szValue
, NULL
, NULL
, (LPBYTE
)szPassword
, &len
)) {
2504 /* Nothing in the registry, get the username and use that as the password */
2505 if (!GetUserNameW(szPassword
, &len
)) {
2506 /* Should never get here, but use an empty password as failsafe */
2507 strcpyW(szPassword
, szEmpty
);
2512 TRACE("Password used for anonymous ftp : (%s)\n", debugstr_w(szPassword
));
2513 lpwfs
->lpszPassword
= heap_strdupW(szPassword
);
2516 lpwfs
->lpszUserName
= heap_strdupW(lpszUserName
);
2517 lpwfs
->lpszPassword
= heap_strdupW(lpszPassword
? lpszPassword
: szEmpty
);
2519 lpwfs
->servername
= heap_strdupW(lpszServerName
);
2521 /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
2522 if (!(lpwfs
->hdr
.dwInternalFlags
& INET_OPENURL
))
2524 INTERNET_ASYNC_RESULT iar
;
2526 iar
.dwResult
= (DWORD_PTR
)lpwfs
->hdr
.hInternet
;
2527 iar
.dwError
= ERROR_SUCCESS
;
2529 SendAsyncCallback(&hIC
->hdr
, dwContext
,
2530 INTERNET_STATUS_HANDLE_CREATED
, &iar
,
2531 sizeof(INTERNET_ASYNC_RESULT
));
2534 SendAsyncCallback(&hIC
->hdr
, dwContext
, INTERNET_STATUS_RESOLVING_NAME
,
2535 (LPWSTR
) lpszServerName
, (strlenW(lpszServerName
)+1) * sizeof(WCHAR
));
2537 sock_namelen
= sizeof(socketAddr
);
2538 if (!GetAddress(lpszServerName
, lpwfs
->serverport
, (struct sockaddr
*)&socketAddr
, &sock_namelen
, szaddr
))
2540 INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED
);
2544 if (socketAddr
.sin_family
!= AF_INET
)
2546 WARN("unsupported address family %d\n", socketAddr
.sin_family
);
2547 INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT
);
2551 SendAsyncCallback(&hIC
->hdr
, dwContext
, INTERNET_STATUS_NAME_RESOLVED
,
2552 szaddr
, strlen(szaddr
)+1);
2555 nsocket
= socket(AF_INET
,SOCK_STREAM
,0);
2558 INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT
);
2562 SendAsyncCallback(&hIC
->hdr
, dwContext
, INTERNET_STATUS_CONNECTING_TO_SERVER
,
2563 szaddr
, strlen(szaddr
)+1);
2565 if (connect(nsocket
, (struct sockaddr
*)&socketAddr
, sock_namelen
) < 0)
2567 ERR("Unable to connect (%d)\n", WSAGetLastError());
2568 INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT
);
2569 closesocket(nsocket
);
2573 TRACE("Connected to server\n");
2574 lpwfs
->sndSocket
= nsocket
;
2575 SendAsyncCallback(&hIC
->hdr
, dwContext
, INTERNET_STATUS_CONNECTED_TO_SERVER
,
2576 szaddr
, strlen(szaddr
)+1);
2578 sock_namelen
= sizeof(lpwfs
->socketAddress
);
2579 getsockname(nsocket
, (struct sockaddr
*) &lpwfs
->socketAddress
, &sock_namelen
);
2581 if (FTP_ConnectToHost(lpwfs
))
2583 TRACE("Successfully logged into server\n");
2592 WININET_Release( &lpwfs
->hdr
);
2596 return lpwfs
->hdr
.hInternet
;
2600 /***********************************************************************
2601 * FTP_ConnectToHost (internal)
2603 * Connect to a ftp server
2610 static BOOL
FTP_ConnectToHost(ftp_session_t
*lpwfs
)
2613 BOOL bSuccess
= FALSE
;
2616 FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2618 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_USER
, lpwfs
->lpszUserName
, 0, 0, 0))
2621 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2624 /* Login successful... */
2625 if (nResCode
== 230)
2627 /* User name okay, need password... */
2628 else if (nResCode
== 331)
2629 bSuccess
= FTP_SendPassword(lpwfs
);
2630 /* Need account for login... */
2631 else if (nResCode
== 332)
2632 bSuccess
= FTP_SendAccount(lpwfs
);
2634 FTP_SetResponseError(nResCode
);
2637 TRACE("Returning %d\n", bSuccess
);
2642 /***********************************************************************
2643 * FTP_GetNextLine (internal)
2645 * Parse next line in directory string listing
2648 * Pointer to beginning of next line
2653 static LPSTR
FTP_GetNextLine(INT nSocket
, LPDWORD dwLen
)
2655 struct timeval tv
= {RESPONSE_TIMEOUT
,0};
2658 LPSTR lpszBuffer
= INTERNET_GetResponseBuffer();
2663 FD_SET(nSocket
, &set
);
2665 while (nRecv
< MAX_REPLY_LEN
)
2667 if (select(nSocket
+1, &set
, NULL
, NULL
, &tv
) > 0)
2669 if (sock_recv(nSocket
, &lpszBuffer
[nRecv
], 1, 0) <= 0)
2671 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS
);
2675 if (lpszBuffer
[nRecv
] == '\n')
2677 lpszBuffer
[nRecv
] = '\0';
2679 TRACE(":%d %s\n", nRecv
, lpszBuffer
);
2682 if (lpszBuffer
[nRecv
] != '\r')
2687 INTERNET_SetLastError(ERROR_INTERNET_TIMEOUT
);
2695 /***********************************************************************
2696 * FTP_SendCommandA (internal)
2698 * Send command to server
2705 static BOOL
FTP_SendCommandA(INT nSocket
, FTP_COMMAND ftpCmd
, LPCSTR lpszParam
,
2706 INTERNET_STATUS_CALLBACK lpfnStatusCB
, object_header_t
*hdr
, DWORD_PTR dwContext
)
2710 DWORD nBytesSent
= 0;
2714 TRACE("%d: (%s) %d\n", ftpCmd
, debugstr_a(lpszParam
), nSocket
);
2718 lpfnStatusCB(hdr
->hInternet
, dwContext
, INTERNET_STATUS_SENDING_REQUEST
, NULL
, 0);
2721 dwParamLen
= lpszParam
?strlen(lpszParam
)+1:0;
2722 len
= dwParamLen
+ strlen(szFtpCommands
[ftpCmd
]) + strlen(szCRLF
);
2723 if (NULL
== (buf
= heap_alloc(len
+1)))
2725 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
2728 sprintf(buf
, "%s%s%s%s", szFtpCommands
[ftpCmd
], dwParamLen
? " " : "",
2729 dwParamLen
? lpszParam
: "", szCRLF
);
2731 TRACE("Sending (%s) len(%d)\n", debugstr_a(buf
), len
);
2732 while((nBytesSent
< len
) && (nRC
!= -1))
2734 nRC
= sock_send(nSocket
, buf
+nBytesSent
, len
- nBytesSent
, 0);
2741 lpfnStatusCB(hdr
->hInternet
, dwContext
, INTERNET_STATUS_REQUEST_SENT
,
2742 &nBytesSent
, sizeof(DWORD
));
2745 TRACE("Sent %d bytes\n", nBytesSent
);
2749 /***********************************************************************
2750 * FTP_SendCommand (internal)
2752 * Send command to server
2759 static BOOL
FTP_SendCommand(INT nSocket
, FTP_COMMAND ftpCmd
, LPCWSTR lpszParam
,
2760 INTERNET_STATUS_CALLBACK lpfnStatusCB
, object_header_t
*hdr
, DWORD_PTR dwContext
)
2763 LPSTR lpszParamA
= heap_strdupWtoA(lpszParam
);
2764 ret
= FTP_SendCommandA(nSocket
, ftpCmd
, lpszParamA
, lpfnStatusCB
, hdr
, dwContext
);
2765 heap_free(lpszParamA
);
2769 /***********************************************************************
2770 * FTP_ReceiveResponse (internal)
2772 * Receive response from server
2775 * Reply code on success
2779 INT
FTP_ReceiveResponse(ftp_session_t
*lpwfs
, DWORD_PTR dwContext
)
2781 LPSTR lpszResponse
= INTERNET_GetResponseBuffer();
2784 char firstprefix
[5];
2785 BOOL multiline
= FALSE
;
2787 TRACE("socket(%d)\n", lpwfs
->sndSocket
);
2789 SendAsyncCallback(&lpwfs
->hdr
, dwContext
, INTERNET_STATUS_RECEIVING_RESPONSE
, NULL
, 0);
2793 if (!FTP_GetNextLine(lpwfs
->sndSocket
, &nRecv
))
2800 if(lpszResponse
[3] != '-')
2803 { /* Start of multiline response. Loop until we get "nnn " */
2805 memcpy(firstprefix
, lpszResponse
, 3);
2806 firstprefix
[3] = ' ';
2807 firstprefix
[4] = '\0';
2812 if(!memcmp(firstprefix
, lpszResponse
, 4))
2820 rc
= atoi(lpszResponse
);
2822 SendAsyncCallback(&lpwfs
->hdr
, dwContext
, INTERNET_STATUS_RESPONSE_RECEIVED
,
2823 &nRecv
, sizeof(DWORD
));
2827 TRACE("return %d\n", rc
);
2832 /***********************************************************************
2833 * FTP_SendPassword (internal)
2835 * Send password to ftp server
2842 static BOOL
FTP_SendPassword(ftp_session_t
*lpwfs
)
2845 BOOL bSuccess
= FALSE
;
2848 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_PASS
, lpwfs
->lpszPassword
, 0, 0, 0))
2851 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2854 TRACE("Received reply code %d\n", nResCode
);
2855 /* Login successful... */
2856 if (nResCode
== 230)
2858 /* Command not implemented, superfluous at the server site... */
2859 /* Need account for login... */
2860 else if (nResCode
== 332)
2861 bSuccess
= FTP_SendAccount(lpwfs
);
2863 FTP_SetResponseError(nResCode
);
2867 TRACE("Returning %d\n", bSuccess
);
2872 /***********************************************************************
2873 * FTP_SendAccount (internal)
2882 static BOOL
FTP_SendAccount(ftp_session_t
*lpwfs
)
2885 BOOL bSuccess
= FALSE
;
2888 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_ACCT
, szNoAccount
, 0, 0, 0))
2891 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2895 FTP_SetResponseError(nResCode
);
2902 /***********************************************************************
2903 * FTP_SendStore (internal)
2905 * Send request to upload file to ftp server
2912 static BOOL
FTP_SendStore(ftp_session_t
*lpwfs
, LPCWSTR lpszRemoteFile
, DWORD dwType
)
2915 BOOL bSuccess
= FALSE
;
2918 if (!FTP_InitListenSocket(lpwfs
))
2921 if (!FTP_SendType(lpwfs
, dwType
))
2924 if (!FTP_SendPortOrPasv(lpwfs
))
2927 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_STOR
, lpszRemoteFile
, 0, 0, 0))
2929 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
2932 if (nResCode
== 150 || nResCode
== 125)
2935 FTP_SetResponseError(nResCode
);
2939 if (!bSuccess
&& lpwfs
->lstnSocket
!= -1)
2941 closesocket(lpwfs
->lstnSocket
);
2942 lpwfs
->lstnSocket
= -1;
2949 /***********************************************************************
2950 * FTP_InitListenSocket (internal)
2952 * Create a socket to listen for server response
2959 static BOOL
FTP_InitListenSocket(ftp_session_t
*lpwfs
)
2961 BOOL bSuccess
= FALSE
;
2962 socklen_t namelen
= sizeof(lpwfs
->lstnSocketAddress
);
2967 lpwfs
->lstnSocket
= socket(AF_INET
, SOCK_STREAM
, 0);
2968 if (lpwfs
->lstnSocket
== -1)
2970 TRACE("Unable to create listening socket\n");
2974 /* We obtain our ip addr from the name of the command channel socket */
2975 lpwfs
->lstnSocketAddress
= lpwfs
->socketAddress
;
2977 /* and get the system to assign us a port */
2978 lpwfs
->lstnSocketAddress
.sin_port
= htons(0);
2980 if (bind(lpwfs
->lstnSocket
,(struct sockaddr
*) &lpwfs
->lstnSocketAddress
, sizeof(lpwfs
->lstnSocketAddress
)) == -1)
2982 TRACE("Unable to bind socket\n");
2986 if (listen(lpwfs
->lstnSocket
, MAX_BACKLOG
) == -1)
2988 TRACE("listen failed\n");
2992 if (getsockname(lpwfs
->lstnSocket
, (struct sockaddr
*) &lpwfs
->lstnSocketAddress
, &namelen
) != -1)
2996 if (!bSuccess
&& lpwfs
->lstnSocket
!= -1)
2998 closesocket(lpwfs
->lstnSocket
);
2999 lpwfs
->lstnSocket
= -1;
3006 /***********************************************************************
3007 * FTP_SendType (internal)
3009 * Tell server type of data being transferred
3015 * W98SE doesn't cache the type that's currently set
3016 * (i.e. it sends it always),
3017 * so we probably don't want to do that either.
3019 static BOOL
FTP_SendType(ftp_session_t
*lpwfs
, DWORD dwType
)
3022 WCHAR type
[] = { 'I','\0' };
3023 BOOL bSuccess
= FALSE
;
3026 if (dwType
& INTERNET_FLAG_TRANSFER_ASCII
)
3029 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_TYPE
, type
, 0, 0, 0))
3032 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
)/100;
3038 FTP_SetResponseError(nResCode
);
3046 #if 0 /* FIXME: should probably be used for FtpGetFileSize */
3047 /***********************************************************************
3048 * FTP_GetFileSize (internal)
3050 * Retrieves from the server the size of the given file
3057 static BOOL
FTP_GetFileSize(ftp_session_t
*lpwfs
, LPCWSTR lpszRemoteFile
, DWORD
*dwSize
)
3060 BOOL bSuccess
= FALSE
;
3064 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_SIZE
, lpszRemoteFile
, 0, 0, 0))
3067 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
3070 if (nResCode
== 213) {
3071 /* Now parses the output to get the actual file size */
3073 LPSTR lpszResponseBuffer
= INTERNET_GetResponseBuffer();
3075 for (i
= 0; (lpszResponseBuffer
[i
] != ' ') && (lpszResponseBuffer
[i
] != '\0'); i
++) ;
3076 if (lpszResponseBuffer
[i
] == '\0') return FALSE
;
3077 *dwSize
= atol(&(lpszResponseBuffer
[i
+ 1]));
3081 FTP_SetResponseError(nResCode
);
3091 /***********************************************************************
3092 * FTP_SendPort (internal)
3094 * Tell server which port to use
3101 static BOOL
FTP_SendPort(ftp_session_t
*lpwfs
)
3103 static const WCHAR szIPFormat
[] = {'%','d',',','%','d',',','%','d',',','%','d',',','%','d',',','%','d','\0'};
3105 WCHAR szIPAddress
[64];
3106 BOOL bSuccess
= FALSE
;
3109 sprintfW(szIPAddress
, szIPFormat
,
3110 lpwfs
->lstnSocketAddress
.sin_addr
.S_un
.S_addr
&0x000000FF,
3111 (lpwfs
->lstnSocketAddress
.sin_addr
.S_un
.S_addr
&0x0000FF00)>>8,
3112 (lpwfs
->lstnSocketAddress
.sin_addr
.S_un
.S_addr
&0x00FF0000)>>16,
3113 (lpwfs
->lstnSocketAddress
.sin_addr
.S_un
.S_addr
&0xFF000000)>>24,
3114 lpwfs
->lstnSocketAddress
.sin_port
& 0xFF,
3115 (lpwfs
->lstnSocketAddress
.sin_port
& 0xFF00)>>8);
3117 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_PORT
, szIPAddress
, 0, 0, 0))
3120 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
3123 if (nResCode
== 200)
3126 FTP_SetResponseError(nResCode
);
3134 /***********************************************************************
3135 * FTP_DoPassive (internal)
3137 * Tell server that we want to do passive transfers
3138 * and connect data socket
3145 static BOOL
FTP_DoPassive(ftp_session_t
*lpwfs
)
3148 BOOL bSuccess
= FALSE
;
3151 if (!FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_PASV
, NULL
, 0, 0, 0))
3154 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
3157 if (nResCode
== 227)
3159 LPSTR lpszResponseBuffer
= INTERNET_GetResponseBuffer();
3163 char *pAddr
, *pPort
;
3165 struct sockaddr_in dataSocketAddress
;
3167 p
= lpszResponseBuffer
+4; /* skip status code */
3168 while (*p
!= '\0' && (*p
< '0' || *p
> '9')) p
++;
3172 ERR("no address found in response, aborting\n");
3176 if (sscanf(p
, "%d,%d,%d,%d,%d,%d", &f
[0], &f
[1], &f
[2], &f
[3],
3179 ERR("unknown response address format '%s', aborting\n", p
);
3182 for (i
=0; i
< 6; i
++)
3185 dataSocketAddress
= lpwfs
->socketAddress
;
3186 pAddr
= (char *)&(dataSocketAddress
.sin_addr
.S_un
.S_addr
);
3187 pPort
= (char *)&(dataSocketAddress
.sin_port
);
3195 nsocket
= socket(AF_INET
,SOCK_STREAM
,0);
3199 if (connect(nsocket
, (struct sockaddr
*)&dataSocketAddress
, sizeof(dataSocketAddress
)))
3201 ERR("can't connect passive FTP data port.\n");
3202 closesocket(nsocket
);
3205 lpwfs
->pasvSocket
= nsocket
;
3209 FTP_SetResponseError(nResCode
);
3217 static BOOL
FTP_SendPortOrPasv(ftp_session_t
*lpwfs
)
3219 if (lpwfs
->hdr
.dwFlags
& INTERNET_FLAG_PASSIVE
)
3221 if (!FTP_DoPassive(lpwfs
))
3226 if (!FTP_SendPort(lpwfs
))
3233 /***********************************************************************
3234 * FTP_GetDataSocket (internal)
3236 * Either accepts an incoming data socket connection from the server
3237 * or just returns the already opened socket after a PASV command
3238 * in case of passive FTP.
3246 static BOOL
FTP_GetDataSocket(ftp_session_t
*lpwfs
, LPINT nDataSocket
)
3248 struct sockaddr_in saddr
;
3249 socklen_t addrlen
= sizeof(saddr
);
3252 if (lpwfs
->hdr
.dwFlags
& INTERNET_FLAG_PASSIVE
)
3254 *nDataSocket
= lpwfs
->pasvSocket
;
3255 lpwfs
->pasvSocket
= -1;
3259 *nDataSocket
= accept(lpwfs
->lstnSocket
, (struct sockaddr
*) &saddr
, &addrlen
);
3260 closesocket(lpwfs
->lstnSocket
);
3261 lpwfs
->lstnSocket
= -1;
3263 return *nDataSocket
!= -1;
3267 /***********************************************************************
3268 * FTP_SendData (internal)
3270 * Send data to the server
3277 static BOOL
FTP_SendData(ftp_session_t
*lpwfs
, INT nDataSocket
, HANDLE hFile
)
3279 BY_HANDLE_FILE_INFORMATION fi
;
3280 DWORD nBytesRead
= 0;
3281 DWORD nBytesSent
= 0;
3282 DWORD nTotalSent
= 0;
3283 DWORD nBytesToSend
, nLen
;
3285 time_t s_long_time
, e_long_time
;
3290 lpszBuffer
= heap_alloc_zero(sizeof(CHAR
)*DATA_PACKET_SIZE
);
3292 /* Get the size of the file. */
3293 GetFileInformationByHandle(hFile
, &fi
);
3298 nBytesToSend
= nBytesRead
- nBytesSent
;
3300 if (nBytesToSend
<= 0)
3302 /* Read data from file. */
3304 if (!ReadFile(hFile
, lpszBuffer
, DATA_PACKET_SIZE
, &nBytesRead
, 0))
3305 ERR("Failed reading from file\n");
3308 nBytesToSend
= nBytesRead
;
3313 nLen
= DATA_PACKET_SIZE
< nBytesToSend
?
3314 DATA_PACKET_SIZE
: nBytesToSend
;
3315 nRC
= sock_send(nDataSocket
, lpszBuffer
, nLen
, 0);
3323 /* Do some computation to display the status. */
3325 nSeconds
= e_long_time
- s_long_time
;
3326 if( nSeconds
/ 60 > 0 )
3328 TRACE( "%d bytes of %d bytes (%d%%) in %d min %d sec estimated remaining time %d sec\n",
3329 nTotalSent
, fi
.nFileSizeLow
, nTotalSent
*100/fi
.nFileSizeLow
, nSeconds
/ 60,
3330 nSeconds
% 60, (fi
.nFileSizeLow
- nTotalSent
) * nSeconds
/ nTotalSent
);
3334 TRACE( "%d bytes of %d bytes (%d%%) in %d sec estimated remaining time %d sec\n",
3335 nTotalSent
, fi
.nFileSizeLow
, nTotalSent
*100/fi
.nFileSizeLow
, nSeconds
,
3336 (fi
.nFileSizeLow
- nTotalSent
) * nSeconds
/ nTotalSent
);
3338 } while (nRC
!= -1);
3340 TRACE("file transfer complete!\n");
3342 heap_free(lpszBuffer
);
3347 /***********************************************************************
3348 * FTP_SendRetrieve (internal)
3350 * Send request to retrieve a file
3353 * Number of bytes to be received on success
3357 static BOOL
FTP_SendRetrieve(ftp_session_t
*lpwfs
, LPCWSTR lpszRemoteFile
, DWORD dwType
)
3363 if (!(ret
= FTP_InitListenSocket(lpwfs
)))
3366 if (!(ret
= FTP_SendType(lpwfs
, dwType
)))
3369 if (!(ret
= FTP_SendPortOrPasv(lpwfs
)))
3372 if (!(ret
= FTP_SendCommand(lpwfs
->sndSocket
, FTP_CMD_RETR
, lpszRemoteFile
, 0, 0, 0)))
3375 nResCode
= FTP_ReceiveResponse(lpwfs
, lpwfs
->hdr
.dwContext
);
3376 if ((nResCode
!= 125) && (nResCode
!= 150)) {
3377 /* That means that we got an error getting the file. */
3378 FTP_SetResponseError(nResCode
);
3383 if (!ret
&& lpwfs
->lstnSocket
!= -1)
3385 closesocket(lpwfs
->lstnSocket
);
3386 lpwfs
->lstnSocket
= -1;
3393 /***********************************************************************
3394 * FTP_RetrieveData (internal)
3396 * Retrieve data from server
3403 static BOOL
FTP_RetrieveFileData(ftp_session_t
*lpwfs
, INT nDataSocket
, HANDLE hFile
)
3405 DWORD nBytesWritten
;
3411 lpszBuffer
= heap_alloc_zero(sizeof(CHAR
)*DATA_PACKET_SIZE
);
3412 if (NULL
== lpszBuffer
)
3414 INTERNET_SetLastError(ERROR_OUTOFMEMORY
);
3420 nRC
= sock_recv(nDataSocket
, lpszBuffer
, DATA_PACKET_SIZE
, 0);
3423 /* other side closed socket. */
3426 WriteFile(hFile
, lpszBuffer
, nRC
, &nBytesWritten
, NULL
);
3430 TRACE("Data transfer complete\n");
3433 heap_free(lpszBuffer
);
3437 /***********************************************************************
3438 * FTPFINDNEXT_Destroy (internal)
3440 * Deallocate session handle
3442 static void FTPFINDNEXT_Destroy(object_header_t
*hdr
)
3444 LPWININETFTPFINDNEXTW lpwfn
= (LPWININETFTPFINDNEXTW
) hdr
;
3449 WININET_Release(&lpwfn
->lpFtpSession
->hdr
);
3451 for (i
= 0; i
< lpwfn
->size
; i
++)
3453 heap_free(lpwfn
->lpafp
[i
].lpszName
);
3455 heap_free(lpwfn
->lpafp
);
3458 static DWORD
FTPFINDNEXT_FindNextFileProc(WININETFTPFINDNEXTW
*find
, LPVOID data
)
3460 WIN32_FIND_DATAW
*find_data
= data
;
3461 DWORD res
= ERROR_SUCCESS
;
3463 TRACE("index(%d) size(%d)\n", find
->index
, find
->size
);
3465 ZeroMemory(find_data
, sizeof(WIN32_FIND_DATAW
));
3467 if (find
->index
< find
->size
) {
3468 FTP_ConvertFileProp(&find
->lpafp
[find
->index
], find_data
);
3471 TRACE("Name: %s\nSize: %d\n", debugstr_w(find_data
->cFileName
), find_data
->nFileSizeLow
);
3473 res
= ERROR_NO_MORE_FILES
;
3476 if (find
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
3478 INTERNET_ASYNC_RESULT iar
;
3480 iar
.dwResult
= (res
== ERROR_SUCCESS
);
3483 INTERNET_SendCallback(&find
->hdr
, find
->hdr
.dwContext
,
3484 INTERNET_STATUS_REQUEST_COMPLETE
, &iar
,
3485 sizeof(INTERNET_ASYNC_RESULT
));
3493 WIN32_FIND_DATAW
*find_data
;
3496 static void FTPFINDNEXT_AsyncFindNextFileProc(task_header_t
*hdr
)
3498 find_next_task_t
*task
= (find_next_task_t
*)hdr
;
3500 FTPFINDNEXT_FindNextFileProc((WININETFTPFINDNEXTW
*)task
->hdr
.hdr
, task
->find_data
);
3503 static DWORD
FTPFINDNEXT_QueryOption(object_header_t
*hdr
, DWORD option
, void *buffer
, DWORD
*size
, BOOL unicode
)
3506 case INTERNET_OPTION_HANDLE_TYPE
:
3507 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
3509 if (*size
< sizeof(ULONG
))
3510 return ERROR_INSUFFICIENT_BUFFER
;
3512 *size
= sizeof(DWORD
);
3513 *(DWORD
*)buffer
= INTERNET_HANDLE_TYPE_FTP_FIND
;
3514 return ERROR_SUCCESS
;
3517 return INET_QueryOption(hdr
, option
, buffer
, size
, unicode
);
3520 static DWORD
FTPFINDNEXT_FindNextFileW(object_header_t
*hdr
, void *data
)
3522 WININETFTPFINDNEXTW
*find
= (WININETFTPFINDNEXTW
*)hdr
;
3524 if (find
->lpFtpSession
->lpAppInfo
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
3526 find_next_task_t
*task
;
3528 task
= alloc_async_task(&find
->hdr
, FTPFINDNEXT_AsyncFindNextFileProc
, sizeof(*task
));
3529 task
->find_data
= data
;
3531 INTERNET_AsyncCall(&task
->hdr
);
3532 return ERROR_SUCCESS
;
3535 return FTPFINDNEXT_FindNextFileProc(find
, data
);
3538 static const object_vtbl_t FTPFINDNEXTVtbl
= {
3539 FTPFINDNEXT_Destroy
,
3541 FTPFINDNEXT_QueryOption
,
3547 FTPFINDNEXT_FindNextFileW
3550 /***********************************************************************
3551 * FTP_ReceiveFileList (internal)
3553 * Read file list from server
3556 * Handle to file list on success
3560 static HINTERNET
FTP_ReceiveFileList(ftp_session_t
*lpwfs
, INT nSocket
, LPCWSTR lpszSearchFile
,
3561 LPWIN32_FIND_DATAW lpFindFileData
, DWORD_PTR dwContext
)
3564 LPFILEPROPERTIESW lpafp
= NULL
;
3565 LPWININETFTPFINDNEXTW lpwfn
= NULL
;
3567 TRACE("(%p,%d,%s,%p,%08lx)\n", lpwfs
, nSocket
, debugstr_w(lpszSearchFile
), lpFindFileData
, dwContext
);
3569 if (FTP_ParseDirectory(lpwfs
, nSocket
, lpszSearchFile
, &lpafp
, &dwSize
))
3572 FTP_ConvertFileProp(lpafp
, lpFindFileData
);
3574 lpwfn
= alloc_object(&lpwfs
->hdr
, &FTPFINDNEXTVtbl
, sizeof(WININETFTPFINDNEXTW
));
3577 lpwfn
->hdr
.htype
= WH_HFTPFINDNEXT
;
3578 lpwfn
->hdr
.dwContext
= dwContext
;
3579 lpwfn
->index
= 1; /* Next index is 1 since we return index 0 */
3580 lpwfn
->size
= dwSize
;
3581 lpwfn
->lpafp
= lpafp
;
3583 WININET_AddRef( &lpwfs
->hdr
);
3584 lpwfn
->lpFtpSession
= lpwfs
;
3585 list_add_head( &lpwfs
->hdr
.children
, &lpwfn
->hdr
.entry
);
3589 TRACE("Matched %d files\n", dwSize
);
3590 return lpwfn
? lpwfn
->hdr
.hInternet
: NULL
;
3594 /***********************************************************************
3595 * FTP_ConvertFileProp (internal)
3597 * Converts FILEPROPERTIESW struct to WIN32_FIND_DATAA
3604 static BOOL
FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp
, LPWIN32_FIND_DATAW lpFindFileData
)
3606 BOOL bSuccess
= FALSE
;
3608 ZeroMemory(lpFindFileData
, sizeof(WIN32_FIND_DATAW
));
3612 SystemTimeToFileTime( &lpafp
->tmLastModified
, &lpFindFileData
->ftLastAccessTime
);
3613 lpFindFileData
->ftLastWriteTime
= lpFindFileData
->ftLastAccessTime
;
3614 lpFindFileData
->ftCreationTime
= lpFindFileData
->ftLastAccessTime
;
3616 /* Not all fields are filled in */
3617 lpFindFileData
->nFileSizeHigh
= 0; /* We do not handle files bigger than 0xFFFFFFFF bytes yet :-) */
3618 lpFindFileData
->nFileSizeLow
= lpafp
->nSize
;
3620 if (lpafp
->bIsDirectory
)
3621 lpFindFileData
->dwFileAttributes
|= FILE_ATTRIBUTE_DIRECTORY
;
3623 if (lpafp
->lpszName
)
3624 lstrcpynW(lpFindFileData
->cFileName
, lpafp
->lpszName
, MAX_PATH
);
3632 /***********************************************************************
3633 * FTP_ParseNextFile (internal)
3635 * Parse the next line in file listing
3641 static BOOL
FTP_ParseNextFile(INT nSocket
, LPCWSTR lpszSearchFile
, LPFILEPROPERTIESW lpfp
)
3643 static const char szSpace
[] = " \t";
3651 lpfp
->lpszName
= NULL
;
3653 if(!(pszLine
= FTP_GetNextLine(nSocket
, &nBufLen
)))
3656 pszToken
= strtok(pszLine
, szSpace
);
3658 * <Permissions> <NoLinks> <owner> <group> <size> <date> <time or year> <filename>
3661 * drwx--s--- 2 pcarrier ens 512 Sep 28 1995 pcarrier
3663 if(!isdigit(pszToken
[0]) && 10 == strlen(pszToken
)) {
3664 if(!FTP_ParsePermission(pszToken
, lpfp
))
3665 lpfp
->bIsDirectory
= FALSE
;
3666 for(i
=0; i
<=3; i
++) {
3667 if(!(pszToken
= strtok(NULL
, szSpace
)))
3670 if(!pszToken
) continue;
3671 if(lpfp
->bIsDirectory
) {
3672 TRACE("Is directory\n");
3676 TRACE("Size: %s\n", pszToken
);
3677 lpfp
->nSize
= atol(pszToken
);
3680 lpfp
->tmLastModified
.wSecond
= 0;
3681 lpfp
->tmLastModified
.wMinute
= 0;
3682 lpfp
->tmLastModified
.wHour
= 0;
3683 lpfp
->tmLastModified
.wDay
= 0;
3684 lpfp
->tmLastModified
.wMonth
= 0;
3685 lpfp
->tmLastModified
.wYear
= 0;
3687 /* Determine month */
3688 pszToken
= strtok(NULL
, szSpace
);
3689 if(!pszToken
) continue;
3690 if(strlen(pszToken
) >= 3) {
3692 if((pszTmp
= StrStrIA(szMonths
, pszToken
)))
3693 lpfp
->tmLastModified
.wMonth
= ((pszTmp
- szMonths
) / 3)+1;
3696 pszToken
= strtok(NULL
, szSpace
);
3697 if(!pszToken
) continue;
3698 lpfp
->tmLastModified
.wDay
= atoi(pszToken
);
3699 /* Determine time or year */
3700 pszToken
= strtok(NULL
, szSpace
);
3701 if(!pszToken
) continue;
3702 if((pszTmp
= strchr(pszToken
, ':'))) {
3703 SYSTEMTIME curr_time
;
3706 lpfp
->tmLastModified
.wMinute
= atoi(pszTmp
);
3707 lpfp
->tmLastModified
.wHour
= atoi(pszToken
);
3708 GetLocalTime( &curr_time
);
3709 lpfp
->tmLastModified
.wYear
= curr_time
.wYear
;
3712 lpfp
->tmLastModified
.wYear
= atoi(pszToken
);
3713 lpfp
->tmLastModified
.wHour
= 12;
3715 TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
3716 lpfp
->tmLastModified
.wHour
, lpfp
->tmLastModified
.wMinute
, lpfp
->tmLastModified
.wSecond
,
3717 lpfp
->tmLastModified
.wYear
, lpfp
->tmLastModified
.wMonth
, lpfp
->tmLastModified
.wDay
);
3719 pszToken
= strtok(NULL
, szSpace
);
3720 if(!pszToken
) continue;
3721 lpfp
->lpszName
= heap_strdupAtoW(pszToken
);
3722 TRACE("File: %s\n", debugstr_w(lpfp
->lpszName
));
3724 /* NT way of parsing ... :
3726 07-13-03 08:55PM <DIR> sakpatch
3727 05-09-03 06:02PM 12656686 2003-04-21bgm_cmd_e.rgz
3729 else if(isdigit(pszToken
[0]) && 8 == strlen(pszToken
)) {
3730 int mon
, mday
, year
, hour
, min
;
3731 lpfp
->permissions
= 0xFFFF; /* No idea, put full permission :-) */
3733 sscanf(pszToken
, "%d-%d-%d", &mon
, &mday
, &year
);
3734 lpfp
->tmLastModified
.wDay
= mday
;
3735 lpfp
->tmLastModified
.wMonth
= mon
;
3736 lpfp
->tmLastModified
.wYear
= year
;
3738 /* Hacky and bad Y2K protection :-) */
3739 if (lpfp
->tmLastModified
.wYear
< 70) lpfp
->tmLastModified
.wYear
+= 2000;
3741 pszToken
= strtok(NULL
, szSpace
);
3742 if(!pszToken
) continue;
3743 sscanf(pszToken
, "%d:%d", &hour
, &min
);
3744 lpfp
->tmLastModified
.wHour
= hour
;
3745 lpfp
->tmLastModified
.wMinute
= min
;
3746 if((pszToken
[5] == 'P') && (pszToken
[6] == 'M')) {
3747 lpfp
->tmLastModified
.wHour
+= 12;
3749 lpfp
->tmLastModified
.wSecond
= 0;
3751 TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
3752 lpfp
->tmLastModified
.wHour
, lpfp
->tmLastModified
.wMinute
, lpfp
->tmLastModified
.wSecond
,
3753 lpfp
->tmLastModified
.wYear
, lpfp
->tmLastModified
.wMonth
, lpfp
->tmLastModified
.wDay
);
3755 pszToken
= strtok(NULL
, szSpace
);
3756 if(!pszToken
) continue;
3757 if(!strcasecmp(pszToken
, "<DIR>")) {
3758 lpfp
->bIsDirectory
= TRUE
;
3760 TRACE("Is directory\n");
3763 lpfp
->bIsDirectory
= FALSE
;
3764 lpfp
->nSize
= atol(pszToken
);
3765 TRACE("Size: %d\n", lpfp
->nSize
);
3768 pszToken
= strtok(NULL
, szSpace
);
3769 if(!pszToken
) continue;
3770 lpfp
->lpszName
= heap_strdupAtoW(pszToken
);
3771 TRACE("Name: %s\n", debugstr_w(lpfp
->lpszName
));
3773 /* EPLF format - http://cr.yp.to/ftp/list/eplf.html */
3774 else if(pszToken
[0] == '+') {
3775 FIXME("EPLF Format not implemented\n");
3778 if(lpfp
->lpszName
) {
3779 if((lpszSearchFile
== NULL
) ||
3780 (PathMatchSpecW(lpfp
->lpszName
, lpszSearchFile
))) {
3782 TRACE("Matched: %s\n", debugstr_w(lpfp
->lpszName
));
3785 heap_free(lpfp
->lpszName
);
3786 lpfp
->lpszName
= NULL
;
3793 /***********************************************************************
3794 * FTP_ParseDirectory (internal)
3796 * Parse string of directory information
3802 static BOOL
FTP_ParseDirectory(ftp_session_t
*lpwfs
, INT nSocket
, LPCWSTR lpszSearchFile
,
3803 LPFILEPROPERTIESW
*lpafp
, LPDWORD dwfp
)
3805 BOOL bSuccess
= TRUE
;
3806 INT sizeFilePropArray
= 500;/*20; */
3807 INT indexFilePropArray
= -1;
3811 /* Allocate initial file properties array */
3812 *lpafp
= heap_alloc_zero(sizeof(FILEPROPERTIESW
)*(sizeFilePropArray
));
3817 if (indexFilePropArray
+1 >= sizeFilePropArray
)
3819 LPFILEPROPERTIESW tmpafp
;
3821 sizeFilePropArray
*= 2;
3822 tmpafp
= heap_realloc_zero(*lpafp
, sizeof(FILEPROPERTIESW
)*sizeFilePropArray
);
3831 indexFilePropArray
++;
3832 } while (FTP_ParseNextFile(nSocket
, lpszSearchFile
, &(*lpafp
)[indexFilePropArray
]));
3834 if (bSuccess
&& indexFilePropArray
)
3836 if (indexFilePropArray
< sizeFilePropArray
- 1)
3838 LPFILEPROPERTIESW tmpafp
;
3840 tmpafp
= heap_realloc(*lpafp
, sizeof(FILEPROPERTIESW
)*indexFilePropArray
);
3844 *dwfp
= indexFilePropArray
;
3849 INTERNET_SetLastError(ERROR_NO_MORE_FILES
);
3857 /***********************************************************************
3858 * FTP_ParsePermission (internal)
3860 * Parse permission string of directory information
3867 static BOOL
FTP_ParsePermission(LPCSTR lpszPermission
, LPFILEPROPERTIESW lpfp
)
3869 BOOL bSuccess
= TRUE
;
3870 unsigned short nPermission
= 0;
3875 if ((*lpszPermission
!= 'd') && (*lpszPermission
!= '-') && (*lpszPermission
!= 'l'))
3881 lpfp
->bIsDirectory
= (*lpszPermission
== 'd');
3887 nPermission
|= (*(lpszPermission
+1) == 'r' ? 1 : 0) << 8;
3890 nPermission
|= (*(lpszPermission
+2) == 'w' ? 1 : 0) << 7;
3893 nPermission
|= (*(lpszPermission
+3) == 'x' ? 1 : 0) << 6;
3896 nPermission
|= (*(lpszPermission
+4) == 'r' ? 1 : 0) << 5;
3899 nPermission
|= (*(lpszPermission
+5) == 'w' ? 1 : 0) << 4;
3902 nPermission
|= (*(lpszPermission
+6) == 'x' ? 1 : 0) << 3;
3905 nPermission
|= (*(lpszPermission
+7) == 'r' ? 1 : 0) << 2;
3908 nPermission
|= (*(lpszPermission
+8) == 'w' ? 1 : 0) << 1;
3911 nPermission
|= (*(lpszPermission
+9) == 'x' ? 1 : 0);
3915 }while (nPos
<= nLast
);
3917 lpfp
->permissions
= nPermission
;
3922 /***********************************************************************
3923 * FTP_SetResponseError (internal)
3925 * Set the appropriate error code for a given response from the server
3930 static DWORD
FTP_SetResponseError(DWORD dwResponse
)
3936 case 425: /* Cannot open data connection. */
3937 dwCode
= ERROR_INTERNET_CANNOT_CONNECT
;
3940 case 426: /* Connection closed, transer aborted. */
3941 dwCode
= ERROR_INTERNET_CONNECTION_ABORTED
;
3944 case 530: /* Not logged in. Login incorrect. */
3945 dwCode
= ERROR_INTERNET_LOGIN_FAILURE
;
3948 case 421: /* Service not available - Server may be shutting down. */
3949 case 450: /* File action not taken. File may be busy. */
3950 case 451: /* Action aborted. Server error. */
3951 case 452: /* Action not taken. Insufficient storage space on server. */
3952 case 500: /* Syntax error. Command unrecognized. */
3953 case 501: /* Syntax error. Error in parameters or arguments. */
3954 case 502: /* Command not implemented. */
3955 case 503: /* Bad sequence of commands. */
3956 case 504: /* Command not implemented for that parameter. */
3957 case 532: /* Need account for storing files */
3958 case 550: /* File action not taken. File not found or no access. */
3959 case 551: /* Requested action aborted. Page type unknown */
3960 case 552: /* Action aborted. Exceeded storage allocation */
3961 case 553: /* Action not taken. File name not allowed. */
3964 dwCode
= ERROR_INTERNET_EXTENDED_ERROR
;
3968 INTERNET_SetLastError(dwCode
);