program wininet_pr_test; {$APPTYPE CONSOLE} uses SysUtils, windows, wininet, inifiles, shellapi; var conn_param,inet_open : hinternet; Ini: Tinifile; sip : String; slogin: String; spas: String; procedure upload(filename:pchar; ftpfilename:pchar); const port=21; begin Ini:=TiniFile.Create(extractfilepath(paramstr(0))+'c:\MyIni.ini'); inet_open:=internetopen('iexplore',INTERNET_OPEN_TYPE_DIRECT,nil,nil,0); sip:=Ini.ReadString('PSS','ip', 'default value'); slogin:=Ini.ReadString('PSS','login', 'default value'); spas:=Ini.ReadString('PSS','pass', 'default value'); sleep(100); conn_param:=internetconnect(inet_open,sip,port,slogin,spas,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0); ftpputfile(conn_param,filename,ftpfilename,FTP_TRANSFER_TYPE_UNKNOWN,0); internetclosehandle(conn_param); internetclosehandle(inet_open) ; end; 

Swears at:


[DCC Error] wininet_pr_test.dpr (41): E2010 Incompatible types: 'string' and 'PWideChar'

PS If you have a comment on the code, I will be grateful. I am an amateur)

    2 answers 2

    And what is there to understand? You are not the right type in the procedure throw ...

     FtpPutFile(hConnect, 'ТЕКС', 'ТЕКС', FTP_TRANSFER_TYPE_BINARY, 0); 

    and you have pchar , and it is necessary string .

    • I understand this, but I can't do it) - Malus
    • found an error: Ini: = TIniFile.Create ('c: \ MyIni.ini'); // that's right - Malus

    It is necessary to make an explicit type conversion:

     ftpputfile(conn_param, string(filename), string(ftpfilename), FTP_TRANSFER_TYPE_UNKNOWN, 0); 

    sleep needs to be removed. What is it for you?

     inet_open := internetopen('iexplore', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0); Ini := TINIFile.Create(ExtractFilePath(paramstr(0)) + 'MyIni.ini'); // будет открыт файл MyIni.ini, который лежит рядом с программой try sip := Ini.ReadString('PSS', 'ip', 'default value'); slogin := Ini.ReadString('PSS', 'login', 'default value'); spas := Ini.ReadString('PSS', 'pass', 'default value'); finally Ini.Free; // созданные объекты нужно уничтожать, когда они больше не нужны, чтобы не было утечек памяти end;