FTP from axapta
From Development axapta By (dahlsgaard Jan)
Add at Class Declaration Of Wininet class The following:
Dllfunction internetconnect; dllfunction ftpgetfile; dllfunction ftpputfile; dllfunction setcurrentdirectory; # localmacro.Ftp_transfer_type_binary2# 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 diecloud
Contents [Hide]
- 1 upload File
- 2 download file
- 3 troubleshooting
- 4 references
|
[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.
Category: