shenzhang 发表于 2015-5-28 10:11:08

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



[*]1 Upload File
[*]2 Download File
[*]3 Troubleshooting
[*]4 References




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);
}
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);
}
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

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.




Category: General development
页: [1]
查看完整版本: FTP from Axapta