如何使用 C# 中的 FTPClient 对象运行 STOR cmd 到大型机上的 FTP 服务器

问题描述 投票:0回答:1

我正在尝试将大型机上的 JCL 代码文件运行到 C# 代码中的 JES。我首先执行 SITE 命令,告诉它文件类型是 JES,然后尝试使用 JCL 代码对 .txt 文件运行 STOR 命令。 SITE命令运行良好并返回成功代码200,但STOR命令失败并抛出超时异常。

using (FtpClient ftp = new FtpClient())
{
    ftp.Host = host;
    ftp.InternetProtocolVersions = FtpIpVersion.IPv4;
    ftp.Credentials = new NetworkCredential("login","pass");
    ftp.DataConnectionType = FtpDataConnectionType.PASV;
    ftp.EncryptionMode = FtpEncryptionMode.None;
    ftp.Port = 21;                    
    ftp.Connect();
    bool isConnected = ftp.IsConnected;
    FtpReply site = ftp.Execute("SITE FILETYPE=JES");
    FtpReply stor = ftp.Execute("STOR " + file);
    ftp.Disconnect();
    ftp.Dispose();
    bool isDisposed = ftp.IsDisposed;

}

c# ftp mainframe
1个回答
0
投票

您不能像这样执行 FTP

STOR
命令。

您使用的

FtpClient
类肯定有一个专门的上传文件的方法。如果是
System.Net.FtpClient
,那么代码将是这样的:

using (Stream ftpStream = ftp.OpenWrite("/remote/path/file.txt"))
using (Stream fileStream = File.OpenRead(@"C:\local\path\file.txt"))
{
    fileStream.CopyTo(ftpStream);
}
© www.soinside.com 2019 - 2024. All rights reserved.