?
Solved

Need to upload a .zip file to existing FTP Server

Posted on 2005-03-16
10
Medium Priority
?
331 Views
Last Modified: 2010-04-01
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
Comment
Question by:ptrennum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13555887
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
 

Author Comment

by:ptrennum
ID: 13555991
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
 
LVL 86

Assisted Solution

by:jkr
jkr earned 1000 total points
ID: 13556158
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
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!

 

Author Comment

by:ptrennum
ID: 13556545
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
 
LVL 86

Expert Comment

by:jkr
ID: 13556575
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
 

Author Comment

by:ptrennum
ID: 13556785
Thanks JKR  just wondering what the "/upload/test.txt"
is meant for in:

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

Accepted Solution

by:
Julian Hansen earned 1000 total points
ID: 13556863
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
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 13556873
Redefinition of the word couple: usually meanse two but in the case where author doesn't check first could also mean few
0
 

Author Comment

by:ptrennum
ID: 13557610
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
 
LVL 86

Expert Comment

by:jkr
ID: 13557721
You'll need to link with wininet.lib
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question