How do I overwrite my files?

0 votes
asked Aug 4, 2011 by Rob T (350 points)
edited Aug 5, 2011

I can't seem to figure out this what seems simple command-

I can upload folders and files based on the value in a textbox (actually a label- same deal)

client.PutFiles(
   "C:\Program Files\DailyLog\Files\*", 
   "/files/logfiles/" & frmMain.lblID.Text & "", 
   FtpBatchTransferOptions.Recursive)

So if there's files in on the server already, and I need to add more or append whats already there, I can't because it says they already exist.

So I tried this based on a search I did-

client.GetUploadStream(
"C:\Program Files\DailyLog\Files\*", 
"/files/logfiles/" & frmMain.lblID.Text & "", 
FtpBatchTransferOptions.Recursive)

But because the value in the frmMain.lblID.Text is a number, I get the following error-

Conversion from string "/files/logfiles/1" to type 'Integer' is not valid. (with "1" being the number in the lblID.Text in my form.

I also tried client.RemoveDirectory("/files/logfiles/" & frmMain.lblID.Text & "")

So how can I solve this?

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Aug 4, 2011 by Lukas Matyska (54,470 points)
edited Aug 5, 2011

To overwrite existing files on target destination, please specify the last parameter to FtpActionOnExistingFiles.OverwriteAll as follows:

client.PutFiles(
    "C:\Program Files\DailyLog\Files\*", 
    string.Format("/files/logfiles/{0}", frmMain.lblID.Text), 
    FtpBatchTransferOptions.Recursive,
    FtpActionOnExistingFiles.OverwriteAll)

Using the string.Format method instead of the & operator should fix the "Conversion from string..." error.

commented Aug 5, 2011 by Rob T (350 points)
edited Aug 5, 2011

Awesome, thanks a ton. Works perfectly.

...