• FTP from Axapta


    FTP from Axapta

    from Development Axapta by (Dahlsgaard Jan)

    add at the class declaration of the WinInet class the following:

    DLLFunction internetConnect;
    DLLFunction ftpGetFile;
    DLLFunction ftpPutFile;
    DLLFunction setCurrentDirectory;   #localmacro.FTP_TRANSFER_TYPE_BINARY
    2
    #endmacro

    and this in the '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);   setCurrentDirectory = new DLLFunction(winInetDLL, 'FtpSetCurrentDirectoryA');
    setCurrentDirectory.returns(ExtTypes::DWord);
    setCurrentDirectory.arg(ExtTypes::DWord,ExtTypes::String);

    and the following methods:

    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(int _hdl, str _name)
    { 
        return setCurrentDirectory.call(_hdl, _name) != 0;
    }

    use the internetconnect method to connect ftp server, ftpgetfile, ftpputfile to get and put files, and ftpSetCurrentDirectory for change current diectory

    Contents

    [hide]

    [edit]Upload File

    static void TestUploadFTP(Args _args)
    {
        int handle;
        WinInet inet = new WinInet();  ;   handle = inet.internetConnect("ftp.company.com","user123","password123");
        inet.FtpSetCurrentDirectory(handle,"docs");
        inet.FtpPutFile(handle,"C:/Dokumente und Einstellungen/User123/Eigene Dateien/test.txt","test.txt");
        inet.internetCloseHandle(handle);
    }

    [edit]Download File

    static void TestUploadFTP(Args _args)
    {
        int handle;
        WinInet inet = new WinInet();  ;   handle = inet.internetConnect("ftp.microsoft.com","","");
        inet.FtpSetCurrentDirectory(handle,"MISC");
        inet.FtpGetFile(handle,"CBCP.TXT","C:/Users/markus/CBCP.TXT");
        inet.internetCloseHandle(handle);  
    }

    [edit]Troubleshooting

    Problem: Connection can be established and directory change works. Download from FTP Server doesnt work, Dynamics AX ist not responding for a while. Afterwards FtpGetFile was not successful.

    Solution: Create an exception for program Ax32.exe in your Windows Firewall

    [edit]References

    development-axapta : Re: How to send file to FTP FTP Sessions(Windows) MSDN

    Since version 4 and in version 2009 you may use the .NET framework inside Dynamics AX.

  • 相关阅读:
    关于JAVA中RSA加签解签,私钥加密公钥解密和公钥加密私钥解密代码详解
    Vue使用总结
    使用ReflectionToStringBuilder实现toString方法
    vue 发送短信验证码倒计时
    个人信息打码
    Token注解防止表单的重复提交
    html选择图片后直接预览
    从分布式一致性谈到CAP理论、BASE理论
    node.js 下依赖Express 实现post 4种方式提交参数
    web前端学习笔记(CSS变化宽度布局)
  • 原文地址:https://www.cnblogs.com/perock/p/2619714.html
Copyright © 2020-2023  润新知