Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to download ftp file by using FtpWebRequest method?

1,509 views
Skip to first unread message

Hike

unread,
Jan 22, 2010, 3:38:01 AM1/22/10
to
Dear all,

I am trying to download ftp file. The following is a example reading one
file. My question is how to download all files(ex. *.txt) in the ftp folder.
Which method should I use?

BTW, when I use the WinAPI and WinInet, the function is working fine.
However, the task will be ran in batch in 64bit machine. It will cause a
exception error. Therefore, I need to try other solutions like this.

Thanks for your help in advance.

code:

System.Net.FtpWebRequest request;
System.Net.FtpWebResponse response;
System.Net.NetworkCredential credential;
Object ftpo;

ftpo = System.Net.WebRequest::Create("ftp://ftp.test.com/Readme.txt");
request = ftpo;

credential = new System.Net.NetworkCredential("username","passoword");
request.set_Credentials(credential);
request.set_Method("RETR");
response = request.GetResponse();
if (response)
info(response.get_StatusDescription());


Axel Kühn

unread,
Jan 22, 2010, 9:08:01 AM1/22/10
to
Hi Hike,

please have look into this thread about ftp downloading.
http://social.msdn.microsoft.com/Forums/en/ncl/thread/079fb811-3c55-4959-85c4-677e4b20bea3

Hope this helps you.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)

Hike

unread,
Jan 24, 2010, 8:27:01 PM1/24/10
to
Dear Axel,

Thanks for your help. This is very clear example. However, this is for .net,
not for x++.

For example, the following code is not supported in Axapta.

"reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;"

Probably it shoudl be wrote like below.

"request.set_Method("RETR");"

I have no idea what the exact code is and how to transfer such codes into
X++. Any idea?

Best regards,
Hike

Axel Kühn

unread,
Jan 25, 2010, 3:33:01 PM1/25/10
to
Hi Hike,

you are right. A 1:1 translation form .NET Code (i.e. C#) to X++ Code is not
possible because of some differneces between the languages.

But the give code in the example should neerly work.
The only part you have to keep in mind are getter and setter.

In .NET getter and setter are implemented with only one method. In X++ this
is not possible.

In .NET you can use "reqFTP.Method = XZY" to set a value.

In X++ you must write "reqFTP.set_Method(XYZ)" to set a value.
But the MorphX Intellisense helps you with it.

To read the property you must use "reqFTP.get_Method ()" in X++.

Please take a look at http://msdn.microsoft.com/en-us/library/cc598160.aspx
for further details.

Sorry that i haven't an working example for you. But i think, after studying
the link above this will not be a hard job for you to make the .NET example
work in X++.

ramya.s...@gmail.com

unread,
Sep 4, 2012, 9:14:12 AM9/4/12
to
can anybody tell wat isrequest.se_Method("RETR") this?

ramya.s...@gmail.com

unread,
Sep 4, 2012, 9:16:08 AM9/4/12
to

> can anybody tell wat is request.set_Method("RETR") is?
Thanks,
Ramya
0 new messages