Инструменты пользователя

Инструменты сайта


axapta:какпослатьфайлпоftp

Раздел: Программирование>ВзаимодействиеСОкружением


Из DevelopmentAxapta (Dahlsgaard Jan)

В Класс/WinInet, добавьте СlassDeclaration следующее:

    DLLFunction _internetConnect;
    DLLFunction _ftpGetFile;
    DLLFunction _ftpPutFile;

и вот это в new:

    _internetConnect = new DLLFunction(_winInet,"InternetConnectA");
    _internetConnect.returns(ExtTypes::DWORD);
    _internetConnect.arg(ExtTypes::DWORD);
    _internetConnect.arg(ExtTypes::STRING);
    _internetConnect.arg(ExtTypes::DWORD);
    _internetConnect.arg(ExtTypes::STRING);
    _internetConnect.arg(ExtTypes::STRING);
    _internetConnect.arg(ExtTypes::DWORD);
    _internetConnect.arg(ExtTypes::DWORD);
    _internetConnect.arg(ExtTypes::DWORD);
 
    _ftpGetFile  = new DLLFunction(_winInet,"FtpGetFileA");
    _ftpGetFile.returns(ExtTypes::DWORD);
    _ftpGetFile.arg(ExtTypes::DWORD);
    _ftpGetFile.arg(ExtTypes::STRING);
    _ftpGetFile.arg(ExtTypes::STRING);
    _ftpGetFile.arg(ExtTypes::DWORD);
    _ftpGetFile.arg(ExtTypes::DWORD);
    _ftpGetFile.arg(ExtTypes::DWORD);
    _ftpGetFile.arg(ExtTypes::DWORD);
 
    _ftpPutFile  = new DLLFunction(_winInet,"FtpPutFileA");
    _ftpPutFile.returns(ExtTypes::DWORD);
    _ftpPutFile.arg(ExtTypes::DWORD);
    _ftpPutFile.arg(ExtTypes::STRING);
    _ftpPutFile.arg(ExtTypes::STRING);
    _ftpPutFile.arg(ExtTypes::DWORD);
    _ftpPutFile.arg(ExtTypes::DWORD);

и следующие функции:

int internetConnect(str 60 _server, str 99 _userName, str 99 _password )
{
    return
_internetConnect.call(_handle,_server,0,_userName,_password,1,0,0);
}
int FtpGetFile(int _hdl, str 255 _remoteFile, str 255 _localFile)
{
    return
_FtpGetFile.call(_hdl,_remoteFile,_localFile,false,0,#FTP_TRANSFER_TYPE_BINARY,0);
}
 
int FtpPutFile(int _hdl, str 255 _localFile, str 255 _remoteFile)
{
    return
_FtpPutFile.call(_hdl,_localFile,_remoteFile,#FTP_TRANSFER_TYPE_BINARY,0);
}
 
boolean ftpSetCurrentDirectory(str _name)
{
    DLLFunction setCurrentDirectory = new DLLFunction(winInetDLL, 'FtpSetCurrentDirectoryA');
    ;
 
    if (connectHandle == 0)
        return false;
 
    setCurrentDirectory.returns(ExtTypes::DWord);
 
    setCurrentDirectory.arg(ExtTypes::DWord,
                            ExtTypes::String);
 
    return setCurrentDirectory.call(connectHandle, _name) != 0;
} 

Используйте internetconnect для соединения с ftp сервером, и ftpgetfile, ftpputfile для получения и посылки файлов, ftpSetCurrentDirectory для смены текущего каталога

XPO файл с добавленными функциями

Exportfile for AOT version 1.0 or later
Formatversion: 1

***Element: CLS

; Axapta Class: WinInet unloaded at Monday 1/9/2006
; --------------------------------------------------------------------------------
  CLSVERSION 1
  
  CLASS #WinInet
    PROPERTIES
      Name                #WinInet
      Extends             #
      RunOn               #Client
    ENDPROPERTIES
    
    METHODS
      Version: 3
      SOURCE #classDeclaration
        #final class WinInet
        #{
        #    DLL _winInet;
        #    DLLFunction _internetOpen;
        #    DLLFunction _internetCloseHandle;
        #    DLLFunction _internetOpenUrl;
        #    DLLFunction _internetReadFile;
        #
        #    int _handle;
        #    int _result;
        #
        #    DLLFunction _internetConnect;
        #    DLLFunction _ftpGetFile;
        #    DLLFunction _ftpPutFile;
        #    DLLFunction _ftpSetCurrentDirectory;
        #    DLLFunction _ftpCommand;
        #    DLLFunction _ftpFindFirstFile;
        #    DLLFunction _ftpDeleteFile;
        #    DLLFunction _ftpRenameFile;
        #    DLLFunction _ftpCreateDirectory;
        #    DLLFunction _ftpRemoveDirectory;
        #    DLLFunction _ftpGetCurrentDirectory;
        #
        #
        #    #define.FTP_TRANSFER_TYPE_BINARY(2)
        #    #define.FTP_TRANSFER_TYPE_UNKNOWN(0)
        #    #define.FTP_TRANSFER_TYPE_ASCII(1)
        #
        #}
      ENDSOURCE
      SOURCE #finalize
        #void finalize()
        #{
        #    this.internetCloseHandle(_handle);
        #}
      ENDSOURCE
      SOURCE #ftpCommand
        #int ftpCommand(int _handler, boolean _expectResponseIn, str 255 _command)
        #{
        #    int _handlerOut;
        #    int _expectResponse;
        #    ;
        #
        #    if (_expectResponseIn)
        #        _expectResponse = 1;
        #    else
        #        _expectResponse = 0;
        #
        #    if(_ftpCommand.call(_handler, _expectResponse, #FTP_TRANSFER_TYPE_ASCII, _command, 0, _handlerOut) == 0)
        #        return 0;
        #    else
        #        return _handlerOut;
        #}
      ENDSOURCE
      SOURCE #ftpCreateDirectory
        #boolean ftpCreateDirectory(int _hdl, str 255 _name)
        #{
        #    if (_ftpCreateDirectory.call(_hdl, _name) == 0)
        #        return false;
        #    else
        #        return true;
        #}
      ENDSOURCE
      SOURCE #ftpDeleteFile
        #boolean ftpDeleteFile(int _hdl, str 255 _file)
        #{
        #    if (_ftpDeleteFile.call(_hdl, _file) == 0)
        #        return false;
        #    else
        #        return true;
        #}
      ENDSOURCE
      SOURCE #ftpGetCurrentDirectory
        #int ftpGetCurrentDirectory(int _hdl, str 255 _remoteFile, str 255 _localFile)
        #{
        #    return 0;//_ftpGetCurrentDirectory.call(_hdl,_remoteFile,_localFile,false,0,#FTP_TRANSFER_TYPE_BINARY,0);
        #}
        #
      ENDSOURCE
      SOURCE #FtpGetFile
        #int ftpGetFile(int _hdl, str 255 _remoteFile, str 255 _localFile)
        #{
        #    return _FtpGetFile.call(_hdl,_remoteFile,_localFile,false,0,#FTP_TRANSFER_TYPE_BINARY,0);
        #}
      ENDSOURCE
      SOURCE #FtpPutFile
        #int ftpPutFile(int _hdl, str 255 _localFile, str 255 _remoteFile)
        #{
        #    return _FtpPutFile.call(_hdl,_localFile,_remoteFile,#FTP_TRANSFER_TYPE_BINARY,0);
        #}
      ENDSOURCE
      SOURCE #ftpRemoveDirectory
        #boolean ftpRemoveDirectory(int _hdl, str 255 _name)
        #{
        #    if (_ftpRemoveDirectory.call(_hdl, _name) == 0)
        #        return false;
        #    else
        #        return true;
        #}
      ENDSOURCE
      SOURCE #ftpRenameFile
        #boolean ftpRenameFile(int _hdl, str 255 _fileOld, str 255 _fileNew)
        #{
        #    if (_ftpRenameFile.call(_hdl, _fileOld, _fileNew) == 0)
        #        return false;
        #    else
        #        return true;
        #}
      ENDSOURCE
      SOURCE #ftpSetCurrentDirectory
        #Boolean ftpSetCurrentDirectory(int _handler, str _name)
        #{
        #    ;
        #
        #    if (_handler == 0)
        #        return false;
        #
        #    if (_ftpSetCurrentDirectory.call(_handler, _name) == 0)
        #        return false;
        #    else
        #        return true;
        #}
        #
      ENDSOURCE
      SOURCE #internetCloseHandle
        #boolean internetCloseHandle(int handle)
        #{
        #    return _internetCloseHandle.call(handle);
        #}
      ENDSOURCE
      SOURCE #internetConnect
        #int internetConnect(str 60 _server, str 99 _userName, str 99 _password )
        #{
        #    return _internetConnect.call(_handle,_server,0,_userName,_password,1,0,0);
        #}
      ENDSOURCE
      SOURCE #internetOpen
        #int internetOpen(str 255 agent,int accessType,str 255 proxyName,str 255 proxyByPass,int flags)
        #{
        #
        #
        #
        #    return _internetOpen.call(agent,accessType,proxyName,proxyByPass,flags);
        #}
      ENDSOURCE
      SOURCE #internetOpenUrl
        #int internetOpenUrl(str 500 url,int flags = 0,int context = 0)
        #{
        #    Binary _headers = new Binary(512);
        #    int hdl = _internetOpenUrl.call(_handle,url,"",-1,flags,context);
        #    return hdl;
        #
        #
        #}
      ENDSOURCE
      SOURCE #internetReadFile
        #str internetReadFile(int hdl)
        #{
        #    Binary _buffer = new Binary(2048);
        #    Binary _bytesRead = new Binary(4);
        #    str result;
        #    boolean ret;
        #    int done = 0;
        #
        #    while (! done)
        #    {
        #        ret = _internetReadFile.call(hdl,_buffer,2000,_bytesRead);
        #        if ((! _bytesRead.dWord(0)) || (! ret))
        #            done = 1;
        #        else
        #        {
        #            result += subStr(_buffer.string(0),1,_bytesRead.dWord(0));
        #        }
        #    }
        #    return ret ? result : "";
        #}
      ENDSOURCE
      SOURCE #new
        #void new()
        #{
        #    try
        #    {
        #        _winInet = new DLL("WinInet");
        #    }
        #    catch(Exception::Internal)
        #    {
        #        infolog.clear();
        #        return;
        #    }
        #
        #    _internetOpen = new DLLFunction(_winInet,"InternetOpenA");
        #    _internetOpen.returns(ExtTypes::DWORD);
        #    _internetOpen.arg(ExtTypes::STRING);
        #    _internetOpen.arg(ExtTypes::DWORD);
        #    _internetOpen.arg(ExtTypes::STRING);
        #    _internetOpen.arg(ExtTypes::STRING);
        #    _internetOpen.arg(ExtTypes::DWORD);
        #
        #    _internetCloseHandle = new DLLFunction(_winInet,"InternetCloseHandle");
        #    _internetCloseHandle.returns(ExtTypes::DWORD);
        #    _internetCloseHandle.arg(ExtTypes::DWORD);
        #
        #    _internetOpenUrl = new DLLFunction(_winInet,"InternetOpenUrlA");
        #    _internetOpenUrl.returns(ExtTypes::DWORD);
        #    _internetOpenUrl.arg(ExtTypes::DWORD);
        #    _internetOpenUrl.arg(ExtTypes::STRING);
        #    _internetOpenUrl.arg(ExtTypes::STRING);
        #    _internetOpenUrl.arg(ExtTypes::DWORD);
        #    _internetOpenUrl.arg(ExtTypes::DWORD);
        #    _internetOpenUrl.arg(ExtTypes::DWORD);
        #
        #    _internetReadFile = new DLLFunction(_winInet,"InternetReadFile");
        #    _internetReadFile.returns(ExtTypes::DWORD);
        #    _internetReadFile.arg(ExtTypes::DWORD);
        #    _internetReadFile.arg(ExtTypes::POINTER);
        #    _internetReadFile.arg(ExtTypes::DWORD);
        #    _internetReadFile.arg(ExtTypes::POINTER);
        #
        #    _handle = this.internetOpen("Axapta",0,"","",0);
        #
        #    _internetConnect = new DLLFunction(_winInet,"InternetConnectA");
        #    _internetConnect.returns(ExtTypes::DWORD);
        #    _internetConnect.arg(ExtTypes::DWORD);
        #    _internetConnect.arg(ExtTypes::STRING);
        #    _internetConnect.arg(ExtTypes::DWORD);
        #    _internetConnect.arg(ExtTypes::STRING);
        #    _internetConnect.arg(ExtTypes::STRING);
        #    _internetConnect.arg(ExtTypes::DWORD);
        #    _internetConnect.arg(ExtTypes::DWORD);
        #    _internetConnect.arg(ExtTypes::DWORD);
        #
        #    _ftpGetFile  = new DLLFunction(_winInet,"FtpGetFileA");
        #    _ftpGetFile.returns(ExtTypes::DWORD);
        #    _ftpGetFile.arg(ExtTypes::DWORD);
        #    _ftpGetFile.arg(ExtTypes::STRING);
        #    _ftpGetFile.arg(ExtTypes::STRING);
        #    _ftpGetFile.arg(ExtTypes::DWORD);
        #    _ftpGetFile.arg(ExtTypes::DWORD);
        #    _ftpGetFile.arg(ExtTypes::DWORD);
        #    _ftpGetFile.arg(ExtTypes::DWORD);
        #
        #    _ftpPutFile  = new DLLFunction(_winInet,"FtpPutFileA");
        #    _ftpPutFile.returns(ExtTypes::DWORD);
        #    _ftpPutFile.arg(ExtTypes::DWORD);
        #    _ftpPutFile.arg(ExtTypes::STRING);
        #    _ftpPutFile.arg(ExtTypes::STRING);
        #    _ftpPutFile.arg(ExtTypes::DWORD);
        #    _ftpPutFile.arg(ExtTypes::DWORD);
        #
        #    _ftpSetCurrentDirectory = new DLLFunction(_winInet, 'FtpSetCurrentDirectoryA');
        #    _ftpSetCurrentDirectory.returns(ExtTypes::DWORD);
        #    _ftpSetCurrentDirectory.arg(ExtTypes::DWORD);
        #    _ftpSetCurrentDirectory.arg(ExtTypes::STRING);
        #
        #    _ftpCommand = new DLLFunction(_winInet, 'FtpCommandA');
        #    _ftpCommand.returns(ExtTypes::DWORD);
        #    _ftpCommand.arg(ExtTypes::DWORD);
        #    _ftpCommand.arg(ExtTypes::DWORD);
        #    _ftpCommand.arg(ExtTypes::DWORD);
        #    _ftpCommand.arg(ExtTypes::STRING);
        #    _ftpCommand.arg(ExtTypes::DWORD);
        #    _ftpCommand.arg(ExtTypes::DWORD);
        #
        #    _ftpDeleteFile = new DLLFunction(_winInet, 'FtpDeleteFileA');
        #    _ftpDeleteFile.returns(ExtTypes::DWORD);
        #    _ftpDeleteFile.arg(ExtTypes::DWORD);
        #    _ftpDeleteFile.arg(ExtTypes::STRING);
        #
        #    _ftpRenameFile = new DLLFunction(_winInet, 'FtpRenameFileA');
        #    _ftpRenameFile.returns(ExtTypes::DWORD);
        #    _ftpRenameFile.arg(ExtTypes::DWORD);
        #    _ftpRenameFile.arg(ExtTypes::STRING);
        #    _ftpRenameFile.arg(ExtTypes::STRING);
        #
        #    _ftpCreateDirectory = new DLLFunction(_winInet, 'FtpCreateDirectoryA');
        #    _ftpCreateDirectory.returns(ExtTypes::DWORD);
        #    _ftpCreateDirectory.arg(ExtTypes::DWORD);
        #    _ftpCreateDirectory.arg(ExtTypes::STRING);
        #
        #    _ftpRemoveDirectory = new DLLFunction(_winInet, 'FtpRemoveDirectoryA');
        #    _ftpRemoveDirectory.returns(ExtTypes::DWORD);
        #    _ftpRemoveDirectory.arg(ExtTypes::DWORD);
        #    _ftpRemoveDirectory.arg(ExtTypes::STRING);
        #
        #    _ftpGetCurrentDirectory = new DLLFunction(_winInet, 'FtpGetCurrentDirectoryA');
        #    _ftpGetCurrentDirectory.returns(ExtTypes::DWORD);
        #    _ftpGetCurrentDirectory.arg(ExtTypes::DWORD);
        #    _ftpGetCurrentDirectory.arg(ExtTypes::STRING);
        #    _ftpGetCurrentDirectory.arg(ExtTypes::STRING);
        #
        #    /*_ftpFindFirstFile = new DLLFunction(_winInet, 'FtpFindFirstFileA');
        #    _ftpFindFirstFile.returns(ExtTypes::DWORD);
        #    _ftpFindFirstFile.arg(ExtTypes::DWORD);
        #    _ftpFindFirstFile.arg(ExtTypes::STRING);*/
        #
        #}
      ENDSOURCE
      SOURCE #ok
        #boolean ok()
        #{
        #    if (_winInet)
        #        return TRUE;
        #    else
        #        return FALSE;
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS

***Element: END

http://groups.yahoo.com/group/development-axapta/message/13410

axapta/какпослатьфайлпоftp.txt · Последнее изменение: 2018/04/13 22:43 (внешнее изменение)