Easy FTP Uploads in your EXEs

One of my projects involves a complex financial database (stored in Access). I wanted to add a feature to the client EXE that allowed testers to FTP their current copy of the database to me so that I could try to reproduce problems without having to reenter all the data. I didn’t see an FTP control handy in VS2003, and I didn’t feel like messing around with Windows built-in FTP command line program, which doesn’t support passive mode & is annoying to pass parameters to.


So I found NcFTP, a free command line FTP program that fit the bill. Specifically, it offers a dedicated “uploader” program called NcFTPPut. Now, the codebehind for my “Upload Database” button looks like this


Private Sub UploadDatabase()
  If MessageBox.Show(“Upload current database for testing? You must be connected to the internet.”, _
      “Confirm Upload”, MessageBoxButtons.YesNo) = DialogResult.Yes Then

    ‘ make temporary copy of database
    Dim currentDB As String = AppConfig.GetDBFileName
    Dim tmpDBName As String = currentDB.Replace(“.mdb”, “-” & _
      System.DateTime.Now.ToString(“M-d-yyyy-h-m”) & “.mdb”)

    System.IO.File.Copy(currentDB, tmpDBName, True)

    ‘ upload using NcFTPPut
    Dim exe As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & _
      “\ncftpput.exe”
    Dim params As String = “-u MyFTPUserName -p FTPPassword ftp.developmentnow.com . “”" & tmpDBName & “”"”
    Try
      Dim myProcess As Process = System.Diagnostics.Process.Start(exe, params)

      myProcess.WaitForExit()

    Catch ex As Exception
      MessageBox.Show(ex.Message, “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error)

    Finally
      ‘ delete temp copy
      System.IO.File.Delete(tmpDBName)
    End Try
  End If
End Sub


It’s simple, but it works. Now whenever testers find problems with the program, they can just click the “Upload Database” button in my app to send me the data I need to reproduce the problem.


 

DevelopmentNow is a new media consulting company that specializes in building integrated mobile web solutions and native apps. For more information on mobile web technology and the services we offer, give us a call at 800.284.3961, or email sales@developmentnow.com.
This entry was posted in Code. Bookmark the permalink.

Comments are closed.

blog comments powered by Disqus