Uploading an FTP File
The simplest way to upload a file to an FTP server involves using the FTPSendFile method. This method connects to the server, grabs the file and then disconnects. To use this method set a few properties and then call the FTPSendFile method:
DO wwFtp && load lib loFtp = CREATEOBJECT("wwFtp") loFtp.cFTPServer="ftp.west-wind.com" loFtp.cFTPSource="c:\temp\wwcgierr.txt" loFtp.cFTPTarget="/uploads/wwcgierr.txt" *** Use passwords if Anonymous is not allowed. * loFtp.cUsername="username" * loFtp.cPassword="password" IF loFtp.FTPSendFile() # 0 ? loFtp.cErrorMsg ENDIF
You can also use the lower level method FTPSendFileEx which allows more control over how the file is sent. This method allows for message events to be fired that you can catch and allow you to display status information. For details see the documentation for this method. This method also allows you to send multiple files to be sent without reconnecting for each file. The basic syntax for this method is:
loFtp=CREATEOBJECT("wwFTP") loFtp.FTPConnect("ftp.west-wind.com") loFtp.FTPSendFileEx("c:\temp\pkzip.exe","/downloads/pkzip.exe") loFtp.FTPSendFileEx("c:\temp\pkunzip.exe","/downloads/pkunzip.exe") loFtp.FTPClose() *** You can also use FTPSendFileEx2 if you run into problems with FTPSendFileEx loFtp.FTPConnect("ftp.west-wind.com") loFtp.FTPSendFileEx2("c:\temp\pkzip.exe","/downloads/pkzip.exe") loFtp.FTPSendFileEx2("c:\temp\pkunzip.exe","/downloads/pkunzip.exe") loFtp.FTPClose()
There's another method FTPSendFileEx2() that has the same signature as FTPSendFileEx() and uses a different WinInet API that is more reliable. If you run into any issues with FtpSendFileEx - occasional dropped connections or upload aborts - try usiong FTPSendFileEx2(). This method does not expose the event postings to let you know upload progress though, so FTPSendFileEx() is still the better choice UNLESS you run into problems.
Comment or report problem with topic