Need to upload a .zip file to existing FTP Server

I need to add ftp functionality to an exisitng MFC based Dialog app.  All that I need to do is upload one .zip file to an exisitng ftp server.  It would be nice if I could add a progress bar as well.

Thanks

PT
ptrennumAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Take a look at e.g. http://www.codeproject.com/internet/FTPClientClass.asp ("FTP Client Class") which supports (among other things) uploading files to FTP servers
0
ptrennumAuthor Commented:
I was kinda hoping for something a little simpler.  That's a pretty extensive client from what i see and the source isn't even a VC project.  I really just need a simple function send xxxx.zip  to  ftp:\\lalala

Thats about it.

PT
0
jkrCommented:
Well, it *is* a VC++ project - even the sample code snippet on the page is enough to create a single function that allows you to upload a file:

void UploadFile ( char* pszSrc)
{

nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo("ftp://ftp.experts-exchange.com", 21, "anonymous", "anonymous@user.com");

// connect to server
ftpClient.Login(logonInfo);

// do file operation

ftpClient.UploadFile(pszSrc, "/upload/test.txt");

// disconnect
ftpClient.Logout();
}
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ptrennumAuthor Commented:
I see what you mean, I am using your func there and added the files needed from the sample project however I get a pile of linker errors.

FTPBackup error LNK2019: unresolved external symbol "public: __thiscall nsFTP::CFTPListParse::CFTPListParse(void)" (??0CFTPListParse@nsFTP@@QAE@XZ) referenced in function "public: bool __thiscall nsFTP::CFTPClient::List(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class nsSP::RCIPtr<class nsFTP::CFTPFileStatus>,class std::allocator<class nsSP::RCIPtr<class nsFTP::CFTPFileStatus> > > &,bool)const " (?List@CFTPClient@nsFTP@@QBE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$RCIPtr@VCFTPFileStatus@nsFTP@@@nsSP@@V?$allocator@V?$RCIPtr@VCFTPFileStatus@nsFTP@@@nsSP@@@std@@@4@_N@Z)

FTPBackup error LNK2019: unresolved external symbol "public: bool __thiscall nsFTP::CFTPListParse::Parse(class nsFTP::CFTPFileStatus &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Parse@CFTPListParse@nsFTP@@QAE_NAAVCFTPFileStatus@2@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: bool __thiscall nsFTP::CFTPClient::List(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class nsSP::RCIPtr<class nsFTP::CFTPFileStatus>,class std::allocator<class nsSP::RCIPtr<class nsFTP::CFTPFileStatus> > > &,bool)const " (?List@CFTPClient@nsFTP@@QBE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@V?$RCIPtr@VCFTPFileStatus@nsFTP@@@nsSP@@V?$allocator@V?$RCIPtr@VCFTPFileStatus@nsFTP@@@nsSP@@@std@@@4@_N@Z)
0
jkrCommented:
You'll need to add the necessary .cpp files from the .zip file available with the article to your project, then you'll have all the functions to link with.
0
ptrennumAuthor Commented:
Thanks JKR  just wondering what the "/upload/test.txt"
is meant for in:

ftpClient.UploadFile(pszSrc, "/upload/test.txt");
0
Julian HansenCommented:
It is very simple with only a couple of API calls

1. Call InternetOpen like so

HINTERNET m_hInetHandle = InternetOpen ( "ArbitaryNameOfMyApp", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 )

2. Call InternetConnect like so

m_hFtpHandle = InternetConnectW (m_hInetHandle, szURL, INTERNET_DEFAULT_FTP_PORT, szUser, szPassword,
                        INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0) ;


in both cases check m_hInetHandle and m_hFtpHandle for NULL values before continuing to the next call

3.  Call FtpPutFile like so

int rv = FtpPutFileW ( m_hFtpHandle, sSourceFile, sTargetFile, iXferFlag, 0 )

sTarget and sSource contain full paths to source and destination. In the case of sTarget it contains the full path from the virtual root you get to with the name and password used

4. When you done close your handles

f ( m_hFtpHandle )
            InternetCloseHandle ( m_hFtpHandle ) ;
if ( m_hInetHandle )
            InternetCloseHandle ( m_hInetHandle ) ;

I used this in small ActiveX control I wrote for uploading files - works very well.

Hope this is useful

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
Redefinition of the word couple: usually meanse two but in the case where author doesn't check first could also mean few
0
ptrennumAuthor Commented:
I get a bunch of linker errors with Julian's method

FTPBackup error LNK2019: unresolved external symbol __imp__InternetOpenA@20 referenced in function "public: void __thiscall CFTPBackupDlg::SendFTP(void)" (?SendFTP@CFTPBackupDlg@@QAEXXZ)

is there a lib or something i need to link in??
0
jkrCommented:
You'll need to link with wininet.lib
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.