Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FTPPutFile Example

Posted on 2009-07-16
10
Medium Priority
?
5,895 Views
Last Modified: 2013-11-23
Hi,
     I recently found some code on the internet to upload a file to my web site but I can't seem to get the parameters correct.

I tried upload_file('123.123.123.123', '/Httpdocs/', 'C:\Test\1TestFile.txt', '/Httpdocs/1TestFile.txt', 'myusername', 'mypassword');

and several variations but nothing seems to work.

Any help appreciated.
function upload_file(remote_server, 
                     directory, 
                     local_file, 
                     remote_file, 
                     user, 
                     pass: PAnsiChar): boolean; 
var hInet, hConnect: HINTERNET; 
    Dir, Put: Boolean; 
begin 
hInet := InternetOpen(nil, INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0); 
hConnect := InternetConnect(hInet, 
                            remote_server, 
                            INTERNET_DEFAULT_FTP_PORT, 
                            user, pass, 
                            INTERNET_SERVICE_FTP, 
                            INTERNET_FLAG_PASSIVE, 
                            0); 
Dir := ftpSetCurrentDirectory(hConnect, directory); 
WaitForSingleObject(Cardinal(Dir), infinite); 
Put := ftpPutFile(hConnect, local_file, remote_file, FTP_TRANSFER_TYPE_BINARY, 0); 
InternetCloseHandle(hInet); 
InternetCloseHandle(hConnect); 
Result:= Put; 
end;

Open in new window

0
Comment
Question by:pr_wainwright
[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
  • 5
  • 5
10 Comments
 
LVL 14

Accepted Solution

by:
flob9 earned 1000 total points
ID: 24867478
Did you try

upload_file('123.123.123.123', '/Httpdocs/', 'C:\Test\1TestFile.txt', '1TestFile.txt', 'myusername', 'mypassword');

or :

upload_file('123.123.123.123', 'Httpdocs/', 'C:\Test\1TestFile.txt', '1TestFile.txt', 'myusername', 'mypassword');
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 24867585
flob9,
         Sorry neither work.

Regards
Paul.
0
 
LVL 14

Expert Comment

by:flob9
ID: 24867636
Try to get the error with InternetGetLastResponseInfo or GetLastError.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:pr_wainwright
ID: 24868135
Flob9,
         I get Error 6 (The Handle is Invalid)

Regards
Paul.
0
 
LVL 14

Expert Comment

by:flob9
ID: 24868298
Check if InternetConnect succeed, and if not, grab the error code.

"I get Error 6 (The Handle is Invalid)" <<< it must be the hConnect
0
 
LVL 14

Expert Comment

by:flob9
ID: 24868305
also check without the INTERNET_FLAG_PASSIVE
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 24869290
flob9,
         How do I use internetGetLastResponseInfo?

Thanks
Paul.
0
 
LVL 1

Author Closing Comment

by:pr_wainwright
ID: 31604143
My companys FTP policy was blocking the code. At home when tested your code worked fine.
Thanks
Paul.
0
 
LVL 14

Expert Comment

by:flob9
ID: 24876526
something like this :
ErrorNum: Cardinal;
  ErrorBuf: string;
  ErrorLen: Cardinal;
 
[...]
 
hConnect := InternetConnect(hInet, 
                            remote_server, 
                            INTERNET_DEFAULT_FTP_PORT, 
                            user, pass, 
                            INTERNET_SERVICE_FTP, 
                            INTERNET_FLAG_PASSIVE, 
                            0); 
 
if InternetGetLastResponseInfo( Errornum, pChar( ErrorBuf ), ErrorLen ) then
begin 
SetLength( ErrorBuf, ErrorLen );
ShowMessage(ErrorBuf);
end

Open in new window

0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 24877075
flob9,
         Thanks for the code.

Regards
Paul.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

664 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