@@ -173,24 +173,7 @@ bool CFtpClient::Upload( const char * pszLocalPath )
173173 }
174174#endif
175175
176- if ( Send ( " TYPE I" ) == false ||
177- Recv ( 200 ) == false )
178- {
179- return false ;
180- }
181-
182- CFtpResponse clsRes;
183-
184- if ( Send ( " PASV" ) == false ||
185- Recv ( clsRes, 227 ) == false )
186- {
187- return false ;
188- }
189-
190- std::string strIp;
191- int iPort;
192-
193- if ( clsRes.GetIpPort ( strIp, iPort ) == false )
176+ if ( SendBinaryPassive () == false )
194177 {
195178 return false ;
196179 }
@@ -200,10 +183,10 @@ bool CFtpClient::Upload( const char * pszLocalPath )
200183 return false ;
201184 }
202185
203- Socket hSocket = TcpConnect ( strIp .c_str (), iPort , m_iTimeout );
186+ Socket hSocket = TcpConnect ( m_strDataIp .c_str (), m_iDataPort , m_iTimeout );
204187 if ( hSocket == INVALID_SOCKET )
205188 {
206- CLog::Print ( LOG_ERROR , " %s TcpConnect(%s:%d) error(%d)" , __FUNCTION__, strIp .c_str (), iPort , GetError () );
189+ CLog::Print ( LOG_ERROR , " %s TcpConnect(%s:%d) error(%d)" , __FUNCTION__, m_strDataIp .c_str (), m_iDataPort , GetError () );
207190 return false ;
208191 }
209192
@@ -220,7 +203,7 @@ bool CFtpClient::Upload( const char * pszLocalPath )
220203
221204 if ( TcpSend ( hSocket, szBuf, iRead ) != iRead )
222205 {
223- CLog::Print ( LOG_ERROR , " %s TcpSend(%s:%d) error(%d)" , __FUNCTION__, strIp .c_str (), iPort , GetError () );
206+ CLog::Print ( LOG_ERROR , " %s TcpSend(%s:%d) error(%d)" , __FUNCTION__, m_strDataIp .c_str (), m_iDataPort , GetError () );
224207 break ;
225208 }
226209 }
@@ -272,24 +255,7 @@ bool CFtpClient::Download( const char * pszFileName, const char * pszLocalPath )
272255 }
273256#endif
274257
275- if ( Send ( " TYPE I" ) == false ||
276- Recv ( 200 ) == false )
277- {
278- return false ;
279- }
280-
281- CFtpResponse clsRes;
282-
283- if ( Send ( " PASV" ) == false ||
284- Recv ( clsRes, 227 ) == false )
285- {
286- return false ;
287- }
288-
289- std::string strIp;
290- int iPort;
291-
292- if ( clsRes.GetIpPort ( strIp, iPort ) == false )
258+ if ( SendBinaryPassive () == false )
293259 {
294260 return false ;
295261 }
@@ -299,10 +265,10 @@ bool CFtpClient::Download( const char * pszFileName, const char * pszLocalPath )
299265 return false ;
300266 }
301267
302- Socket hSocket = TcpConnect ( strIp .c_str (), iPort , m_iTimeout );
268+ Socket hSocket = TcpConnect ( m_strDataIp .c_str (), m_iDataPort , m_iTimeout );
303269 if ( hSocket == INVALID_SOCKET )
304270 {
305- CLog::Print ( LOG_ERROR , " %s TcpConnect(%s:%d) error(%d)" , __FUNCTION__, strIp .c_str (), iPort , GetError () );
271+ CLog::Print ( LOG_ERROR , " %s TcpConnect(%s:%d) error(%d)" , __FUNCTION__, m_strDataIp .c_str (), m_iDataPort , GetError () );
306272 return false ;
307273 }
308274
@@ -342,6 +308,35 @@ bool CFtpClient::Download( const char * pszFileName, const char * pszLocalPath )
342308 return true ;
343309}
344310
311+ /* *
312+ * @ingroup FtpStack
313+ * @brief FTP 서버로 binary type 및 passive mode 명령을 전송한다.
314+ * @returns 성공하면 true 를 리턴하고 그렇지 않으면 false 를 리턴한다.
315+ */
316+ bool CFtpClient::SendBinaryPassive ( )
317+ {
318+ if ( Send ( " TYPE I" ) == false ||
319+ Recv ( 200 ) == false )
320+ {
321+ return false ;
322+ }
323+
324+ CFtpResponse clsRes;
325+
326+ if ( Send ( " PASV" ) == false ||
327+ Recv ( clsRes, 227 ) == false )
328+ {
329+ return false ;
330+ }
331+
332+ if ( clsRes.GetIpPort ( m_strDataIp, m_iDataPort ) == false )
333+ {
334+ return false ;
335+ }
336+
337+ return true ;
338+ }
339+
345340/* *
346341 * @ingroup FtpStack
347342 * @brief FTP 서버로 명령을 전송한다.
0 commit comments