Want to get up to speed on the latest Visual Basic programming? Includes Visual Basic 6 and Visual InterDev 6. Check out our training programs at http://www.codeoftheweek.com/vbtraining.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html
This issue enhances the code introduced in issue number 54 and 56. It shows how to use the Microsoft WININET.DLL to upload a file to any FTP server. It does not use the Microsoft Internet Controls, so there is one less file you have to worry about including with your application.
Be sure to refer to the documentation from issue 56 ( http://www.codeoftheweek.com/issues/0056.html ) for complete details on the events raised to show the status of your transfer.
If you have any questions about using this module, let us know at questions@codeoftheweek.com
Public Sub UploadWithStatus()
Starts the upload process based on the values supplied to the properties: ServerName, SourceFilename, DestinationFilename, Username, and Password. SourceFilename should contain the full path and filename of the file which you are sending to the FTP server. DestinationFilename should also contain the full path and filename of the file that will be saved on the FTP server relative to the FTP server (for example: /users/home/david/files.txt).
Various errors will be raised to indicate failure. If the file succeeds it will return to the caller without any errors being raised.
The below sample will upload a file called c:\temp\test.txt to a file called /usr/home/david/testfile.txt on ftp server ftp.codeoftheweek.com
Set ftp = New cFTP ftp.DestinationFilename = "/usr/home/david/testfile.txt" ftp.SourceFilename = "c:\temp\test.txt" ftp.ServerName = "ftp.codeoftheweek.com" ftp.Username = "user" ftp.Password = "password" On Error Resume Next ftp.UploadWithStatus If Err Then MsgBox Err.Description End If
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0106.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html