Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

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
0
ptrennum
Asked:
ptrennum
  • 4
  • 4
  • 2
2 Solutions
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now