我正尝试从我的android应用程序连接到FTP服务器,如果没有异常,则一切正常,但是如果我超时,则Android应用程序将关闭。
我确实为FTP连接创建了一个线程,但是仍然存在相同的问题。
any1能否指出正确的方向,说明如何在Android中正确建立FTP连接。
如果我将它集成到Windows中,则PS完全可以正常工作,并且可以正确管理异常。
FTP连接的代码为:
IdFTP1.ConnectTimeout := 1000;
IdFTP1.Passive := True;
IdFTP1.Host := ftp_server;
IdFTP1.Username:= ftp_user;
IdFTP1.Password:= ftp_pass;
if ftp_port<> '' then begin
Try
IdFTP1.Port := StrToInt(ftp_port);
except
IdFTP1.Port := 21;
End;
end
else
IdFTP1.Port := 21;
TTask.Run(
procedure
var
ftp_error : Boolean;
begin
Try
ftp_error := False;
IdFTP1.Connect;
IdFTP1.Passive := true;
if ftp_folder= '' then
IdFTP1.Put( System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,'temp.txt'), ftp_file, False )
else begin
if ftp_folder[length(ftp_folder)] <> '/' then
ftp_folder:= ftp_folder+ '/';
IdFTP1.Put( System.IOUtils.TPath.Combine(System.IOUtils.tpath.getdocumentspath,'temp.txt'), ftp_folder+ftp_file, False );
end;
IdFTP1.Disconnect;
except
ftp_error := True;
End;
TThread.Queue(nil,
procedure
begin
if not ftp_error then begin
showmessage('FTP connection correct');
end
else begin
showmessage('Error FTP');
end;
end);
end);
这是IdFTP1的配置,以防万一出现问题(如果我没有记错所有默认选项的话)
Windows上的日志文件更新:
Stat Connected.
Recv 26/02/2019 9:51:03: 220-FileZilla Server 0.9.60 beta<EOL>220-written by Tim Kosse (tim.kosse@filezilla-project.org)<EOL>220 Please visit https://filezilla-project.org/<EOL>
Sent 26/02/2019 9:51:03: HOST [172.26.29.170]<EOL>
Recv 26/02/2019 9:51:03: 500 Syntax error, command unrecognized.<EOL>
Sent 26/02/2019 9:51:03: USER admin<EOL>
Recv 26/02/2019 9:51:03: 331 Password required for admin<EOL>
Sent 26/02/2019 9:51:03: PASS admin<EOL>
Recv 26/02/2019 9:51:03: 230 Logged on<EOL>
Sent 26/02/2019 9:51:03: FEAT<EOL>
Recv 26/02/2019 9:51:03: 211-Features:<EOL> MDTM<EOL> REST STREAM<EOL> SIZE<EOL> MLST type*;size*;modify*;<EOL> MLSD<EOL> UTF8<EOL> CLNT<EOL> MFMT<EOL> EPSV<EOL> EPRT<EOL>211 End<EOL>
Sent 26/02/2019 9:51:03: CLNT Indy 10.6.1.5182<EOL>
Recv 26/02/2019 9:51:03: 200 Don't care<EOL>
Sent 26/02/2019 9:51:03: TYPE I<EOL>
Recv 26/02/2019 9:51:03: 200 Type set to I<EOL>
Sent 26/02/2019 9:51:03: SYST<EOL>
Recv 26/02/2019 9:51:03: 215 UNIX emulated by FileZilla<EOL>
Sent 26/02/2019 9:51:03: TYPE I<EOL>
Recv 26/02/2019 9:51:03: 200 Type set to I<EOL>
Sent 26/02/2019 9:51:03: PASV<EOL>
Recv 26/02/2019 9:51:03: 227 Entering Passive Mode (172,26,29,170,232,171)<EOL>
Sent 26/02/2019 9:51:03: STOR camacho/p1<EOL>
Recv 26/02/2019 9:51:03: 150 Opening data channel for file upload to server of "/camacho/p1"<EOL>
Recv 26/02/2019 9:51:03: 226 Successfully transferred "/camacho/p1"<EOL>
Sent 26/02/2019 9:51:03: QUIT<EOL>
Recv 26/02/2019 9:51:03: 221 Goodbye<EOL>
Stat Disconnected.