FTP from Axapta

本文介绍如何在Axapta中使用DLL函数实现FTP文件上传和下载功能,并提供了具体的代码示例,包括连接FTP服务器、更改目录、上传及下载文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

转载于:https://www.cnblogs.com/perock/archive/2012/08/02/2619714.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值