Dynamics AX的FTP [英] Dynamics AX FTP

查看:120
本文介绍了Dynamics AX的FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题要发送的FTP CSV文件,我用的AxaptaPedia发现以下code:

I have problems to send csv file on ftp, I use the following code found on AxaptaPedia:

object ftpo;
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;
;
reader = new System.IO.StreamReader(strfmt("%1%2","\\\\Server\\directory\\","Export.csv"));
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes( reader.ReadToEnd() );
reader.Close();

ftpo = System.Net.WebRequest::Create(strfmt("%1%2","ftp://IP_Address/directory/","Export.csv"));
request = ftpo;

credential = new System.Net.NetworkCredential("user","password");
request.set_Credentials(credential);
request.set_ContentLength(bytes.get_Length());
request.set_Method("STOR");

requestStream = request.GetRequestStream();
requestStream.Write(bytes,0,bytes.get_Length());
requestStream.Close();

ftpResponse = request.GetResponse();
response = ftpResponse;
info(response.get_StatusDescription());

没有编译错误,不执行错误,但文件在我的FTP不上传,我认为这个问题是在路径文件编码,我尝试过其他的解决方案无果。我要处理的FTP批量发送文件,它的工作使用WinInet类,但WININET类不能在服务器端运行的,所以我必须使用.NET框架。 任何意见或解决方案是值得欢迎的。

No compilation errors, no execution errors but file is not uploaded on my FTP, I think the problem is on the path file coding, i tried other solutions without results. I want to process send file on FTP in batch, it works using wininet class but wininet class can't be run on server side so I must use .net framework. Any ideas or solution is welcome

感谢帮助

推荐答案

我有过这样的问题,将文件保存到任何网络目录中,而不仅仅是FTP。什么工作对我来说是创建为服务器和文件名,并使用串联,而不是字符串格式(StrFmt)独立变量。由于某些原因,字符串格式化只是默默无法正常使用,而串联不工作:

I have had this issue with saving files to any network directory and not just FTP. What worked for me was to create separate variables for both the server and the file name and use concatenation instead of string format (StrFmt). for some reason the string formatting just silently fails to work, while concatenation does work:

str  server = "\\\\Server\\directory\\";
str  fileName = "Export.csv";
Net.WebRequest::Create(server + fileName);

另外最好做法不会到c这些值硬$ C $。您应该创建一个参数表来存储这些值,并调用表查找值,并将其分配给您的变量或使用一个对话框来获取用户输入在运行时。这避免了任何在将来从具有改变code如果FTP服务器的改变并且还避免在该文件名被改变,以及问题。

Also best practice would not be to hard code either of these values. you should either create a parameter table to store these values and make a call to the table to find the values and assign them to your variables or use a dialog to get the input from the user at run-time. This avoids anyone in the future from having to change the code if the FTP server changes and also avoids issues where the file name is changed as well.

这篇关于Dynamics AX的FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆