FTP from axapta

Source: Internet
Author: User
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:  

    • General development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.