Re: [twsocket] ICSFTP delete file after transfer completed.
Thank you for pointing me into the right direction! 2016-01-28 14:09 GMT+02:00 Angus Robertson - Magenta Systems Ltd < an...@magsys.co.uk>: > > I want to delete a file after succesfully uploading to ftp. > > I use overbyteicsftp client and the following code: > > Is this the correct approach to delete the file after complete > > transfer to ftp? > > > if icsFtp.Put then begin > > if DeleteFile(nume_fisier) then > > In a crude program, you can get away with this. But there is a risk > the FTP server may have reported the upload successful when only a > partial file was received, or not received atall. > > It's much safer to actually check the file exists after being uploaded > and is the correct size and maybe has not been corrupted during upload, > perhaps by running a CRC32 or MD5 check. > > How you check a file depends on the FTP server functionality, the best > ways are using the MLST or MDTM commands, but you may need to use LIST > if these are not supported. > > I suggest you look at the FtpCheckFile function in TMagFtp at: > > http://www.magsys.co.uk/delphi/magxfer.asp > > Or just use that component which has extensive error handling. > > Angus > > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] ICSFTP delete file after transfer completed.
Hello, I want to delete a file after succesfully uploading to ftp. I use overbyteicsftp client and the following code: Is this the correct approach to delete the file after complete transfer to ftp? Thank you begin icsFtp := TFtpclient.Create(nil); try icsFtp.OnProgress64 := form1.icsFtpONProgress; icsftp.OnDisplay:= form1.DisplayHandler; icsFtp.HostName := host_ftp; icsftp.Port:=port_ftp; icsFtp.UserName := username_ftp; icsFtp.PassWord := password_ftp; icsFtp.LocalFileName := nume_fisier; icsFtp.HostDirName := directory_ftp; icsFtp.HostFileName := ExtractFileName(icsFtp.LocalFileName); icsFtp.BandwidthLimit := 0; icsFtp.Passive := True; icsFtp.Binary := True; icsFtp.MultiThreaded := true; form1.Log('start conectare la "' + icsFtp.HostName+'"'); if not icsFtp.Connect then begin form1.Log('eroare de conectare la "' + icsFtp.HostName + '" => ' + icsFtp.LastResponse); Exit; end; try form1.Log('conectat cu succes la "' + icsFtp.HostName+'"'); form1.Log('start incarcare fisier "' + icsFtp.HostFileName + '"'); if icsftp.cwd then begin form1.Log('directorul curent a fost schimbat cu succes in "'+icsftp.HostDirName+'" => '+icsftp.LastResponse); end else begin form1.Log('eroare la schimbarea directorului curent "'+icsftp.HostDirName+'" => '+icsftp.LastResponse); end; if icsFtp.Put then begin form1.Log('incarcat cu succes "' + icsFtp.HostFileName + '"'); form1.Log('sterg fisierul "'+icsFtp.HostFileName+ '"'); {sterg fisierul} if DeleteFile(nume_fisier) then form1.Log('fisierul "'+nume_fisier+'" a fost STERS') else form1.Log('fisierul "'+nume_fisier+'" nu a putut fi sters => EROARE: '+IntToStr(GetLastError)); end else begin form1.Log('eroare la incarcarea fisierului "' + icsFtp.HostFileName + '" => ' + icsFtp.LastMultiResponse); end; finally form1.Log('inchid conexiunea cu serverul de ftp'); icsFtp.Quit; end; finally icsFtp.Free; end; -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be