00001
00002
00003
00004
00005
00006 #include "fsFtpConnection.h"
00007 #include "fsInternetSession.h"
00008 #include "common.h"
00009 #include "system.h"
00010 #include <stdio.h>
00011
00012 fsFtpConnection::fsFtpConnection()
00013 {
00014 m_bPassiveMode = FALSE;
00015 }
00016
00017 fsFtpConnection::~fsFtpConnection()
00018 {
00019
00020 }
00021
00022 fsInternetResult fsFtpConnection::Connect(LPCSTR pszServer, LPCSTR pszUser, LPCSTR pszPassword, INTERNET_PORT nPort)
00023 {
00024 fsInternetResult ir;
00025
00026 if (!m_pSession)
00027 return IR_NOTINITIALIZED;
00028
00029
00030 HINTERNET hSession = m_pSession->GetHandle ();
00031
00032 if (!hSession)
00033 return IR_NOTINITIALIZED;
00034
00035 if (m_hServer)
00036 InternetCloseHandle (m_hServer);
00037
00038 m_hServer = InternetConnect (hSession, pszServer, nPort, pszUser, pszPassword,
00039 INTERNET_SERVICE_FTP, m_bPassiveMode ? INTERNET_FLAG_PASSIVE : 0,
00040 NULL);
00041
00042 if (m_hServer == NULL)
00043 {
00044 ir = fsWinInetErrorToIR ();
00045 DialogFtpResponse ();
00046 if (ir == IR_EXTERROR)
00047 ReceiveExtError ();
00048 return ir;
00049 }
00050
00051 DialogFtpResponse ();
00052
00053 m_strServer = pszServer;
00054 m_uPort = nPort;
00055
00056 return IR_SUCCESS;
00057 }
00058
00059 void fsFtpConnection::UsePassiveMode(BOOL bUse)
00060 {
00061 m_bPassiveMode = bUse;
00062 }
00063
00064 void fsFtpConnection::ReceiveExtError()
00065 {
00066 SAFE_DELETE_ARRAY (m_pszLastError);
00067 DWORD dwLen = 0;
00068 DWORD dwErr;
00069
00070 InternetGetLastResponseInfo (&dwErr, NULL, &dwLen);
00071
00072 if (::GetLastError () == ERROR_INSUFFICIENT_BUFFER)
00073 {
00074 dwLen ++;
00075 fsnew (m_pszLastError, char, dwLen);
00076 InternetGetLastResponseInfo (&dwErr, m_pszLastError, &dwLen);
00077 }
00078 }
00079
00080 fsInternetResult fsFtpConnection::SetCurrentDirectory(LPCSTR pszDir)
00081 {
00082 char szCmd [1000];
00083 sprintf (szCmd, "CWD %s", pszDir);
00084 Dialog (IFDD_TOSERVER, szCmd);
00085
00086
00087 if (!FtpSetCurrentDirectory (m_hServer, pszDir))
00088 {
00089 fsInternetResult ir = fsWinInetErrorToIR ();
00090 if (ir == IR_EXTERROR)
00091 ReceiveExtError ();
00092 DialogFtpResponse ();
00093 return ir;
00094 }
00095
00096 DialogFtpResponse ();
00097 return IR_SUCCESS;
00098 }
00099
00100 BOOL fsFtpConnection::IsPassiveMode()
00101 {
00102 return m_bPassiveMode;
00103 }