|
|
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
Не могу понять в чем трабл. Создаю ftp соединение с серваком. На запрос BOOL temp = FtpGetFile ... выдает постоянно FALSE, пришлось закомментить. Хотел решить вопрос через Read(fileBuf, FILEBUFLEN) и Write(fileBuf, numBytes). Выкидывает на эсепшне, даже не проходя serverFile = pFtpConnection->OpenFile(fileName); Кто подскажет, что делать???? // BOOL temp = FtpGetFile(pFtpConnection, "F5154.txt", "F5154.txt", true, INTERNET_FLAG_RELOAD,FTP_TRANSFER_TYPE_BINARY,0); CInternetSession sess(_T("MyProgram/1.0")); CFtpConnection* pFtpConnection = NULL; CInternetSessionEx* pSession; address = "addr.com"; username = "user"; password = "passw"; CString fileName = "F5154.txt"; CString fileNameLocal = "F5154.txt"; CInternetFile* serverFile = NULL; CFile localFile(fileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary); try { // Request a connection to ftp.microsoft.com. Default // parameters mean that we'll try with username = ANONYMOUS // and password set to the machine name @ domain name pSession = new CInternetSessionEx(AfxGetApp()->m_pszAppName, 1, INTERNET_OPEN_TYPE_DIRECT, 0, 0, INTERNET_FLAG_DONT_CACHE); pSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 500); pSession->SetOption(INTERNET_OPTION_CONNECT_RETRIES, 2); pSession->EnableStatusCallback(); pFtpConnection = pSession->GetFtpConnection(address.c_str(), username.c_str(), password.c_str(), INTERNET_DEFAULT_FTP_PORT); // use a file find object to enumerate files CFtpFileFind finder(pFtpConnection); // BOOL temp = FtpGetFile(pFtpConnection, "F5154.txt", "F5154.txt", true, INTERNET_FLAG_RELOAD,FTP_TRANSFER_TYPE_BINARY,0); localPath = "C:\\Temp"; SetCurrentDirectory(localPath.c_str()); try { serverFile = pFtpConnection->OpenFile(fileName); ULONGLONG fileLength; ULONGLONG currentProgress = 0; ASSERT(serverFile); const int FILEBUFLEN = 1024; char fileBuf[FILEBUFLEN]; UINT numBytes; short sent = 0; while (numBytes = serverFile->Read(fileBuf, FILEBUFLEN)) { if (!stopDownload) { localFile.Write(fileBuf, numBytes); currentProgress += FILEBUFLEN; short toSend = static_cast<short>(100 * currentProgress/fileLength); if (sent + 2 < toSend) { sent = toSend; } } else break; } serverFile->Close(); localFile.Flush(); localFile.Close(); if (stopDownload) { if (!DeleteFile(fileName)) AfxMessageBox("Can't delete local file."); } } catch (CInternetException* pEx) { TCHAR sz[1024]; pEx->GetErrorMessage(sz, 1024); string msg = "InternetException: "; msg += sz; AfxMessageBox(msg.c_str()); pEx->Delete(); if (serverFile) serverFile->Close(); localFile.Close(); if (!DeleteFile(fileName)) AfxMessageBox("Can't delete local file."); } catch (...) { AfxMessageBox("FTP Update: unhandled exception."); if (serverFile) serverFile->Close(); localFile.Close(); if (!DeleteFile(fileName)) AfxMessageBox("Can't delete local file."); } } catch (CInternetException* pEx) { TCHAR sz[1024]; pEx->GetErrorMessage(sz, 1024); printf("ERROR! %s\n", sz); pEx->Delete(); } ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 23.09.2005, 14:44 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
Anton M.Не могу понять в чем трабл. Создаю ftp соединение с серваком. На запрос BOOL temp = FtpGetFile ... выдает постоянно FALSE, А какая ошибка то? FtpGetFile() это команда WinAPI. Она не делает исключений, поэтому ее ошибку через try{}catch не поймать. Попробуй так: Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 23.09.2005, 19:06 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
Ага, выснил в чем проблема! Оказывается он ругается на неправильный хэндл, передаваемый в FtpGetFile. GetLastError() = ERROR_INVALID_HANDLE. Отсюда другая проблема-непонятно с чего он ругается на хэндл, т.к.: Так я создаю соединение: CFtpConnection* pFtpConnection = NULL; CInternetSessionEx* pSession; pSession = new CInternetSessionEx(AfxGetApp()->m_pszAppName, 1, INTERNET_OPEN_TYPE_DIRECT, 0, 0, INTERNET_FLAG_DONT_CACHE); pSession->SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 500); pSession->SetOption(INTERNET_OPTION_CONNECT_RETRIES, 2); pSession->EnableStatusCallback(); pFtpConnection = pSession->GetFtpConnection(address.c_str(), username.c_str(), password.c_str(), INTERNET_DEFAULT_FTP_PORT); FtpGetFile(pSession, fileName, fileName, FALSE, 0, FTP_TRANSFER_TYPE_BINARY, 0) В чем же некорректность передаваемого хэндла??? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.09.2005, 12:49 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
Anton M. pFtpConnection = pSession->GetFtpConnection(address.c_str(), username.c_str(), password.c_str(), INTERNET_DEFAULT_FTP_PORT); FtpGetFile(pSession, fileName, fileName, FALSE, 0, FTP_TRANSFER_TYPE_BINARY, 0) В чем же некорректность передаваемого хэндла??? В том, что туда надо передавать хендл FTP соединения, а не указатель на объект CInternetSessionEx. FtpGetFile(pFtpConnection, fileName, fileName, FALSE, 0, FTP_TRANSFER_TYPE_BINARY, 0) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 26.09.2005, 19:25 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
Господа, помогите! Ничего не пойму, всячески уже делал, и пытался закачать FtpGetFile и GetFile и качать побайтно, ничего не выходит. Говорит мол хэнл эррор, а на мой взгляд все вероно. Насчет последнего поста - на вход подавал pFtpConnection, все равно говорит ERROR HANDLE. HINTERNET hInternetSession; HINTERNET hInternetConnect; DWORD dwContext; hInternetSession = InternetOpen("Ftp download client", // agent INTERNET_OPEN_TYPE_PRECONFIG, // access NULL, NULL, 0); // defaults LPCTSTR lpszDirectory="/"; BOOL CurDir = FtpSetCurrentDirectory(hInternetSession, lpszDirectory); hInternetConnect = InternetConnect(hInternetSession, address.c_str),INTERNET_DEFAULT_FTP_PORT ,username.c_str(), password.c_str(), INTERNET_SERVICE_FTP, INTERNET_FLAG_HYPERLINK, dwContext); BOOL dlFile = FtpGetFile(hInternetConnect,"ftp://ftp.xtrapilot.com/5154.txt","c:\F5154.TXT", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0); dlFile опять 0! ПочемуУ?? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.09.2005, 18:39 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
>>BOOL CurDir = FtpSetCurrentDirectory(hInternetSession, lpszDirectory); BOOL CurDir = FtpSetCurrentDirectory( hInternetConnect , lpszDirectory); >>BOOL dlFile = FtpGetFile(hInternetConnect,"ftp://ftp.xtrapilot.com/5154.txt", >>"c:\F5154.TXT", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0); "ftp://ftp.xtrapilot.com/5154.txt" - Это что ? А вообще вот куски моего обучения работы с FTP. Как ни странно - работает. Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.09.2005, 19:00 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
Anton M.Насчет последнего поста - на вход подавал pFtpConnection, все равно говорит ERROR HANDLE. Ааааа... там наверное надо что-то вроде pFtpConnection->Handle подавать :) А по поводу этого куска, в общем все правильно. Кроме одного: Код: plaintext Код: plaintext ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 27.09.2005, 19:20 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
ZrenBy>>BOOL CurDir = FtpSetCurrentDirectory(hInternetSession, ... Spasibo, pomoglo! ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 28.09.2005, 12:10 |
|
||
|
FTP clent. Не могу стянуть файл с сервака. В чем трабл?
|
|||
|---|---|---|---|
|
#18+
White Owl Anton M.Насчет последнего поста - на вход подавал pFtpConnection, все равно говорит ERROR HANDLE. Ааааа... там наверное надо что-то вроде pFtpConnection->Handle подавать :) А по поводу этого куска, в общем все правильно. Кроме одного: Код: plaintext Код: plaintext Toje spasibo bolshoe! A vot naschet pFtpConnection->m_hConnection идея хорошая, но есть загвоздка m_hConnection стоит в protected в afxinet.h, поэтому его не видать из моего класса ... =) ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 28.09.2005, 12:13 |
|
||
|
|

start [/forum/topic.php?fid=57&tid=2032716]: |
0ms |
get settings: |
8ms |
get forum list: |
11ms |
check forum access: |
5ms |
check topic access: |
5ms |
track hit: |
38ms |
get topic data: |
9ms |
get forum data: |
2ms |
get page messages: |
34ms |
get tp. blocked users: |
1ms |
| others: | 209ms |
| total: | 322ms |

| 0 / 0 |
