zoukankan      html  css  js  c++  java
  • 【转】AX 2012 upload file to FTP with batch processing support

    One of a very common requirements for any ERP systems is to have FTP file upload support to upload files from AX to FTP server. We do have many libraries, tools available to do that. However, it is best to have native X++ code without referencing any DLLs to upload your files to FTP from AX. Following code shows the example of uploading files to FTP.

    The code written below can be easily used to upload files, However, if you have to process this as a batch you need to consider that batch runs on server/CIL and for this you need to set permissions and also if that still doesn't work, you can change the method to static server.

    private server static void sendToFTP()
    {
        System.Object ftpo;
        System.Object ftpResponse;
        System.Net.FtpWebRequest request;
        System.IO.StreamReader reader;
        System.IO.Stream requestStream;
        System.Byte[] bytes;
        
        System.Text.Encoding utf8;
        System.Net.FtpWebResponse response;
        System.Object credential;
        HOSInventParameters hosInventParameters;
     
        int             fileCount;
        System.Array    files;
        int             i;
        str             nextFile;
        Filename        filepath;
        Filename        fileType,fileNameString;
        FileNameType    pattern = '*.TXT';
        FileName        ftpFileName,fileName;
     
     
        select firstOnly custInventParameters;
        new InteropPermission(InteropKind::ClrInterop).assert();
     
     
     
        files           = System.IO.Directory::GetFiles(custInventParameters.PartsFileLocation, pattern);
     
        if (files)
        {
            fileCount =    files.get_Length();
     
            for(i=0; i < fileCount; i++)
            {
                nextFile    = files.GetValue(i);
     
                [filepath, filename, fileType] = fileNameSplit(nextFile);
                fileNameString= filename + fileType;
                ftpFileName = custInventParameters.PartsFTPAddress + '/'+ custInventParameters.PartsFTPLocation + '/' + fileNameString;
     
                reader = new System.IO.StreamReader(nextFile);
                utf8 = System.Text.Encoding::get_UTF8();
                bytes = utf8.GetBytes( reader.ReadToEnd() );
                reader.Close();
                // little workaround to get around the casting in .NET
                ftpo = System.Net.WebRequest::Create(ftpFileName);
                request = ftpo;
     
                credential = newSystem.Net.NetworkCredential(custInventParameters.PartsUserId,custInventParameters.PartsFTPPassword);
                request.set_Credentials(credential);
                request.set_ContentLength(bytes.get_Length());
                request.set_Method('STOR');
                // "Bypass" a HTTP Proxy (FTP transfer through a proxy causes an exception)
                // request.set_Proxy( System.Net.GlobalProxySelection::GetEmptyWebProxy() );
                requestStream = request.GetRequestStream();
                requestStream.Write(bytes,0,bytes.get_Length());
                requestStream.Close();
     
                ftpResponse = request.GetResponse();
                response = ftpResponse;
                info(response.get_StatusDescription());
            }
        }
     
        CodeAccessPermission::revertAssert();
    }
    

      

    原文地址:https://microsoftdax.blogspot.jp/2015/05/ax-2012-upload-file-to-ftp-with-batch.html

  • 相关阅读:
    SharePoint部署webpart时候,报错:部署步骤“回收 IIS 应用程序池”中出现错误: 无效命名空间 解决方案
    免费的分布式的自动化测试工具
    https://github.com/dotnetcore
    SharePoint2013与SharePoint2016语言切换原理以及如何使用代码进行语言切换
    微软开源最强Python自动化神器Playwright!不用写一行代码!
    B站播单按时间统计进度
    AF_INET与PF_INET的区别
    git显示:fatal: index file smaller than expected
    Unix系统中信号SIGKILL和SIGSTOP
    GTM、UTC和C/C++中的时间处理
  • 原文地址:https://www.cnblogs.com/bjdc/p/7226347.html
Copyright © 2011-2022 走看看