11#include " TestFtpStack.h"
22
3+ void PrintUsage ( const char * pszProgram )
4+ {
5+ printf ( " [Usage] %s {ftp IP} {user id} {password} upload_folder {remote folder path} {local folder path}\n " , pszProgram );
6+ }
7+
38int main ( int argc, char * argv[] )
49{
510#ifdef WIN32
611 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF );
712#endif
813
9- if ( argc != 4 )
14+ if ( argc <= 5 )
1015 {
11- printf ( " [Usage] %s {ftp IP} {user id} {password} \n " , argv[0 ] );
16+ PrintUsage ( argv[0 ] );
1217 return 0 ;
1318 }
1419
1520 const char * pszServerIp = argv[1 ];
1621 const char * pszUserId = argv[2 ];
1722 const char * pszPassWord = argv[3 ];
23+ const char * pszCommand = argv[4 ];
1824
1925 CFtpClient clsFtp;
2026
@@ -24,18 +30,46 @@ int main( int argc, char * argv[] )
2430 if ( clsFtp.Connect ( pszServerIp, 21 , true ) == false )
2531 {
2632 printf ( " clsFtp.Connect(%s) error\n " , pszServerIp );
33+ return 0 ;
34+ }
35+
36+ if ( clsFtp.Login ( pszUserId, pszPassWord ) == false )
37+ {
38+ printf ( " login error\n " );
39+ return 0 ;
2740 }
28- else
41+
42+ if ( !strcmp ( pszCommand, " upload_folder" ) )
2943 {
30- if ( clsFtp.Login ( pszUserId, pszPassWord ) == false )
44+ if ( argc <= 6 )
45+ {
46+ PrintUsage ( argv[0 ] );
47+ return 0 ;
48+ }
49+
50+ const char * pszRemoteFolder = argv[5 ];
51+ const char * pszLocalFolder = argv[6 ];
52+ FILE_LIST clsFileList;
53+ FILE_LIST ::iterator itFL;
54+
55+ if ( clsFtp.ChangeDirectory ( pszRemoteFolder ) == false )
3156 {
32- printf ( " login error\n " );
57+ printf ( " clsFtp.ChangeDirectory(%s) error\n " , pszRemoteFolder );
58+ return 0 ;
3359 }
34- else
60+
61+ CDirectory::FileList ( pszLocalFolder, clsFileList );
62+
63+ for ( itFL = clsFileList.begin (); itFL != clsFileList.end (); ++itFL )
3564 {
36- clsFtp.ChangeDirectory ( " /home/test" );
37- clsFtp.Upload ( " C:\\ Temp\\ ÇѱÛ.jpg" );
38- clsFtp.Download ( " ÇѱÛ.jpg" , " C:\\ Temp\\ ÇѱÛ2.jpg" );
65+ std::string strPath = pszLocalFolder;
66+ CDirectory::AppendName ( strPath, itFL->c_str () );
67+
68+ if ( clsFtp.Upload ( strPath.c_str () ) == false )
69+ {
70+ printf ( " clsFtp.Upload(%s) error\n " , strPath.c_str () );
71+ break ;
72+ }
3973 }
4074 }
4175
0 commit comments