Overwriting file on upload

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
Posts: 4
Joined: Wed 24 Oct 2018 06:04

Overwriting file on upload

Post by HBL » Fri 03 May 2019 08:10

I have a program that sync. files between a local drive and the files on our SFTP server.

I noticed a bug (I belive it is). When I try to sync a file that is smaller then the file on the SFTP, it seems it upload the file, but in reality its not.

Uploading a smaller file from local HDD to SFTP where a larger file is present - Not Working
Uploading a larger file from local HDD to SFTP where a smaller file is present - Working
Uploading a file that dosnt exists on SFTP - Working.

My quick fix is to delete the SFTP file first (if exists)

I use the following code to upload a file:
Handle := FSFTPClient.OpenFile(RemotePath + RemoteFile, fmCreateNew, [], [bmWrite, bmDelete], [amWriteData]);
BufSize := (High(Word)+1) * ((BUF_SIZE * 1024 * 1024) div High(Word));
Setlength(Buf, BufSize);

FileOffset := 0;
BufSize := 0;
PartUploadDataProc(Buf, BufSize, EOF);
FSFTPClient.WriteFile(Handle, FileOffset, Buf, 0, BufSize);
Inc(FileOffset, BufSize);

EOF = True;

Devart Team
Posts: 2806
Joined: Wed 30 Jul 2014 07:16

Re: Overwriting file on upload

Post by ViktorV » Mon 06 May 2019 12:26

To solve your task, you can try using the fmCreateOrTruncate parameter in the TScSFTPClient.OpenFile method.

Post Reply