Discussion:
How to download ftp file by using FtpWebRequest method?
(too old to reply)
Hike
2010-01-22 08:38:01 UTC
Permalink
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
2010-01-22 14:08:01 UTC
Permalink
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)
Post by Hike
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.
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());
Hike
2010-01-25 01:27:01 UTC
Permalink
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
Post by Axel Kühn
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)
Post by Hike
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.
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
2010-01-25 20:33:01 UTC
Permalink
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++.
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Hike
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
Post by Axel Kühn
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)
Post by Hike
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.
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());
r***@gmail.com
2012-09-04 13:14:12 UTC
Permalink
can anybody tell wat isrequest.se_Method("RETR") this?
Post by Hike
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.
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());
r***@gmail.com
2012-09-04 13:16:08 UTC
Permalink
can anybody tell wat is request.set_Method("RETR") is?
Thanks,
Ramya
Post by Hike
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.
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());
Loading...