function UploadToFTP(file: string ; PathSrv : string): Boolean;
var
server, port, user , password: string;
SR : TSearchRec;
begin
Result := True;
FEventLogger := TEventLogger.Create('Upload FTP');
if file <> '' then
begin
try
server := FServer;
port := FPort;
user := FUserName;
password:= FPassword;
FindFirst(file, faArchive, SR);
try // try except
idftp1.Host:= server;
idftp1.Port := StrToInt(port);
idftp1.Username:= user;
idftp1.Password:= password;
idftp1.Connect();
idftp1.Put(file,PathSrv+SR.Name);
except on E: Exception do begin
Result:= False;
FEventLogger.LogMessage('Exception : ' + E.Message , EVENTLOG_ERROR_TYPE , 0, 2);
WriteToLog('Exception: '+ file+' error message: '+ E.Message);
end;
end;
finally
end;
end;
end;
所以我有这个函数可以在有时很慢的网络上上传ftp上传到一些大文件。我已经对它进行了测试,它运行正常,但在慢速网络上,我在99%的时间内都会遇到这种情况。
The specified network name is no longer available.
这是一种非常奇怪的行为,因为FTP位于没有断开连接问题的服务器上。我也尝试观看,它启动文件上传,它几乎所有上传之前抛出此错误。因此,例如,如果我有一个100MB的文件,它会执行99MB的上传,然后抛出错误。
任何想法导致此错误的原因或我该怎么办?
还有时我还有其他错误
Socket Error # 10054
Connection reset by peer.
要提一下,我试图使用filezilla上传这些文件并且它有效,所以问题出在该代码的某个地方,我可能会错过一些东西。