hi,
some time ago I have written an application using ftp
using API; to be more precise, I have used Class, but
I rember that there was corrispondent WIN32 call,
without use Class.
in xxx.h use
// Implementation
protected:
CInternetSession *m_pInt1_Sess ; CFtpConnection *m_pFtp1_Conn ;
in xxx.cpp,
CString str;
if (!str.LoadString(IDS_APPNAME))
str = _T("AppUnknown"

;
m_pInt1_Sess= new CInternetSession(str,1,PRE_CONFIG_INTERNET_ACCESS);
if (!m_pInt1_Sess)
{
AfxMessageBox(IDS_INTSES_BAD, MB_ICONSTOP);
m_pFtp1_Conn = NULL;
return TRUE;
}
else
{
AfxMessageBox(IDS_INTSES_OK, MB_OK);
}
CWaitCursor cursor;
try
{
m_pFtp1_Conn = m_pInt1_Sess->GetFtpConnection( m_cFtp1_SrvNam, m_cFtp1_SrvUsr, m_cFtp1_SrvPwd ) ;
}
catch (CInternetException* pEx)
{
// catch errors from WinINet
TCHAR szErr[1024];
if (pEx->GetErrorMessage(szErr, 1024))
AfxMessageBox(szErr, MB_ICONSTOP);
else
{
AfxMessageBox("Exception", MB_ICONSTOP); pEx->Delete();
}
m_pFtp1_Conn = NULL;
}
....
if( m_pFtp1_Conn )
{
/* if( m_pFtp1_Conn->SetCurrentDirectory( m_cFileType.Left(1) ) ) // "M"
AfxMessageBox("SetCurrentDirectory", MB_OK ) ;
else
AfxMessageBox("SetCurrentDirectory", MB_ICONSTOP ) ;
*/
CString strDirName ;
if( m_pFtp1_Conn->GetCurrentDirectory( strDirName ) )
AfxMessageBox(strDirName, MB_OK ) ;
else
AfxMessageBox("GetCurrentDirectory", MB_ICONSTOP ) ;
}
.....
if( m_pFtp1_Conn->PutFile( src_full, new_remote,
FTP_TRANSFER_TYPE_ASCII, 1 ) )
AfxMessageBox("PutFile", MB_OK ) ;
else
{
char messaggio[80];
sprintf( messaggio, "PutFile %ld", GetLastError() ) ;
AfxMessageBox(messaggio, MB_ICONSTOP ) ;
return ;
}
.....
if (m_pFtp1_Conn != NULL)
{
m_pFtp1_Conn->Close();
delete m_pFtp1_Conn;
AfxMessageBox("FtpConnection Closed", MB_OK);
}
if (m_pInt1_Sess != NULL)
{
m_pInt1_Sess->Close();
delete m_pInt1_Sess;
AfxMessageBox("InetSession Closed", MB_OK);
}
-------------------------------
Sorry for confusion, but I have copied/paste from many
parts of program: there was dialogs, buttons, ecc:
however the schema is standard:
- Open something ( Internet Session, FTP Connection )
- Perform Operations ( Put, CD, GEt ... )
- Close ( FTP Conn, Intern Sess )
If you will use API, follow the same schema, and look for
similar name call.
bye.