# connecting to FTP server via AX 2012

**URL:** <https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190>\
**Category:** Developer Forum\
**Created:** [December 9, 2014, 5:38pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190 "2014-12-09T17:38:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmedo](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Ahmedo](https://www.dynamicsuser.net/u/Ahmedo)\
**Post date:** [December 9, 2014, 5:38pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/1 "2014-12-09T17:38:46Z")

</div>

hI ,

I want to connect to FTP server via ax 2012 and retrieve the list of files still present in the repository directory.

can you help me?

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [December 9, 2014, 6:12pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/2 "2014-12-09T18:12:09Z")

</div>

It’s been already discussed several times - a search engine will help you to find what you need, without having to ask here. [Dynamics AX 2009: FTP Adapter for AIF](https://erpcoder.wordpress.com/2012/07/08/dynamics-ax-2009-ftp-adapter-for-aif/) is one of things that you would find.

---

<div class="post-metadata">

**Author:** ![Ahmedo](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Ahmedo](https://www.dynamicsuser.net/u/Ahmedo)\
**Post date:** [December 10, 2014, 6:41pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/3 "2014-12-10T18:41:38Z")

</div>

Is there a way to do that without AIF ?

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [December 10, 2014, 6:52pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/4 "2014-12-10T18:52:59Z")

</div>

Of course, because it has nothing to do with AIF at all. The point is using .NET API for FTP through .NET Interop; that the example above uses the code for implementing an AIF adapter is irrelevant. You’ll rarely get _an example_ that implements exactly what you need. Use your intellect to identify what’s related to FTP.

---

<div class="post-metadata">

**Author:** ![Ahmedo](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Ahmedo](https://www.dynamicsuser.net/u/Ahmedo)\
**Post date:** [December 12, 2014, 10:35am UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/5 "2014-12-12T10:35:05Z")

</div>

i have try that but i get this error Impossible create ‘CLRObject’

static void uploadTestFile(Args \_args) {

System.Object ftpo;

System.Object ftpResponse;

System.Net.FtpWebRequest request;

System.IO.StreamReader reader;

System.IO.Stream requestStream;

System.Byte[] bytes;

System.Net.NetworkCredential credential;

System.String xmlContent;

System.Text.Encoding utf8;

System.Net.FtpWebResponse response;

;

// Read file

reader = new System.IO.StreamReader(“ftp://net.site.com/user/test.xml”);

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(“ftp://net.site.com/user/test.xml”);

request = ftpo;

credential = new System.Net.NetworkCredential(“log”,“pass”);

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

}

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [December 12, 2014, 7:30pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/6 "2014-12-12T19:30:35Z")

</div>

Which object are you talking about? There is more than one in your code.

---

<div class="post-metadata">

**Author:** ![Ahmedo](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Ahmedo](https://www.dynamicsuser.net/u/Ahmedo)\
**Post date:** [December 13, 2014, 11:49am UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/7 "2014-12-13T11:49:23Z")

</div>

the issue i d’t understand what ax mean by _[CLRObject could not be created](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCAQFjAA&url=http%3A%2F%2Fblogs.msdn.com%2Fb%2Faxsupport%2Farchive%2F2012%2F10%2F09%2Fclrobject-could-not-be-created-error-when-entering-tools-options-in-microsoft-dynamics-ax-2012.aspx&ei=3CaMVPn7HcjoaNq5gbgD&usg=AFQjCNGkA5wSH08TeQTpUP7FvBfEMyu3fw&sig2=AH1wRLFkRMeMsc15PSnIXg&bvm=bv.81828268,d.d2s)_

but i thank the problem is to connecting to FTP so the object is response

i thank i have an error in this code

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [December 14, 2014, 8:00am UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/8 "2014-12-14T08:00:07Z")

</div>

It means that an exception is thrown when creating a .NET object (CLR stands from Common Language Runtime, but you can safely think about it as .NET). You won’t be able to fix it unless you identify which object (which line of code) it’s related to. That’s the same for all exceptions, being thrown by AX runtime or CLR.

---

<div class="post-metadata">

**Author:** ![Ahmedo](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Ahmedo](https://www.dynamicsuser.net/u/Ahmedo)\
**Post date:** [December 18, 2014, 2:42pm UTC](https://www.dynamicsuser.net/t/connecting-to-ftp-server-via-ax-2012/56190/9 "2014-12-18T14:42:58Z")

</div>

thank you ,

now i can read , and upload file to FTP server , now i m looking for how to delete file into FTP,
