Dynamics AX 2009:如何从 AOS 上的批处理作业进行 FTP

发布于 2024-12-10 20:48:00 字数 226 浏览 4 评论 0原文

经过多次搜索 AX 中 FTP 文件的方法后,我很高兴发现了 WinInet 类,它或多或少只是同名 .DLL 的包装器。我以为我的问题已经解决了!然而,我并不知道该类有一个主要的致命弱点——它不能批量运行(在服务器上)。

有人能指出我正确的方向吗?具体来说,我想在服务器运行的批处理作业中将文件上传(FTP put)到另一台服务器(作为对相关文件具有管理员权限的服务用户运行)。有人吗?

After quite a few searches for ways to FTP files in AX, I was happy to discover the WinInet class, which is more or less just a wrapper for the .DLL of the same name. I thought my problems were solved! I was not aware, however, that the class had a major Achilles heel -- it doesn't run in batch (on a server).

Can anybody point me in the right direction? Specifically, I want to upload (FTP put) a file to another server in a server-run batch job (running as a service user with admin rights to the file in question). Anybody?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏尔 2024-12-17 20:48:00

Axaptapedia 中还有另一个使用 .NET 类进行 FTP 的示例。它与 10p 的示例代码有很大不同,值得一看...

根据我自己的经验,我最终编写并从命令行调用一个 bat 文件来传递 ftp 命令,因为我们需要使用特殊的 FTP 客户端!以下是使用 shell 脚本的两个示例 - Net Time && 运行进程

There is another example of using .NET classes for FTP in Axaptapedia. It is different enough from 10p's example code to take a look...

In my own experience I ended up writing and then calling a bat file from the command line to pass in ftp commands as we needed to use a special FTP client! Here are two examples of using shell scripting - Net Time && Run a Process.

七堇年 2024-12-17 20:48:00

在 AX 中使用 .NET 类,例如,以下代码登录到 FTP 服务器并重命名其中的文件:

str ftpHostName = 'ftp.microsoft.com'; // without "ftp://", only name
str username    = 'myloginname';
str password    = 'mypassword';
str oldname     = 'oldfilename';
str newname     = 'newfilename';

System.Net.Sockets.Socket socket;
System.Net.Dns dns;
System.Net.IPHostEntry  hostEntry;
System.Net.IPAddress[] addresses;
System.Net.IPAddress    address;
System.Net.IPEndPoint endPoint;

void sendCommand(str _command)
{
    System.Text.Encoding ascii;
    System.Byte[] bytes;
    ;

    ascii = System.Text.Encoding::get_ASCII();
    bytes = ascii.GetBytes(_command + '\r\n');
    socket.Send(bytes, bytes.get_Length(), System.Net.Sockets.SocketFlags::None);
}
;

socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily::InterNetwork, System.Net.Sockets.SocketType::Stream, System.Net.Sockets.ProtocolType::Tcp);
hostEntry = System.Net.Dns::GetHostEntry(ftpHostName);

addresses = hostEntry.get_AddressList();
address = addresses.GetValue(0);

info(address.ToString());

endPoint = new System.Net.IPEndPoint(address, 21);
socket.Connect(endPoint);

sendCommand(strfmt("USER %1", username));
sendCommand(strfmt("PASS %1", password));
sendCommand(strfmt("RNFR %1", oldname));
sendCommand(strfmt("RNTO %1", newname));

这只是一个示例,但请随意使用任何标准 FTP 命令稍微简化此代码。如果这个概念不清楚,请告诉我。

Use .NET classes in AX, e.g. following code logs into the FTP server and renames the file there:

str ftpHostName = 'ftp.microsoft.com'; // without "ftp://", only name
str username    = 'myloginname';
str password    = 'mypassword';
str oldname     = 'oldfilename';
str newname     = 'newfilename';

System.Net.Sockets.Socket socket;
System.Net.Dns dns;
System.Net.IPHostEntry  hostEntry;
System.Net.IPAddress[] addresses;
System.Net.IPAddress    address;
System.Net.IPEndPoint endPoint;

void sendCommand(str _command)
{
    System.Text.Encoding ascii;
    System.Byte[] bytes;
    ;

    ascii = System.Text.Encoding::get_ASCII();
    bytes = ascii.GetBytes(_command + '\r\n');
    socket.Send(bytes, bytes.get_Length(), System.Net.Sockets.SocketFlags::None);
}
;

socket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily::InterNetwork, System.Net.Sockets.SocketType::Stream, System.Net.Sockets.ProtocolType::Tcp);
hostEntry = System.Net.Dns::GetHostEntry(ftpHostName);

addresses = hostEntry.get_AddressList();
address = addresses.GetValue(0);

info(address.ToString());

endPoint = new System.Net.IPEndPoint(address, 21);
socket.Connect(endPoint);

sendCommand(strfmt("USER %1", username));
sendCommand(strfmt("PASS %1", password));
sendCommand(strfmt("RNFR %1", oldname));
sendCommand(strfmt("RNTO %1", newname));

This is just an example but feel free to use any standard FTP command slightly mpdifying this code. Let me know if the concept is unclear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文