【发布时间】:2015-05-20 18:46:01
【问题描述】:
我使用 cmd (Windows) 将文件发送到 IBM 大型机并且工作正常,如下所示:
Open abc.wyx.state.aa.bb
User
Pass
lcd c:\Transfer>
Put examplefile 'ABCD.AA.C58FC.ABC1FD.ZP3ABC'
close
bye
我需要将其转换为 C#。我一直在尝试使用FtpWebRequest,但没有运气。我不知道如何包含我猜的数据集。当我运行应用程序时,出现以下错误:
((System.Exception)(ex)).Message "远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问)。" 550 无法存储 远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问)。
((FtpWebResponse)ex.Response).StatusDescription "550 无法存储 /'ABCD.AA.C58FC.ABC1FD.ZP3ABC/examplefile'\r\n"
这是我在 C# 中得到的内容
string user = "user";
string pwd = "password";
string ftpfullpath = @"ftp://abc.wyx.state.aa.bb//'ABCD.AA.C58FC.ABC1FD.ZP3ABC'/examplefile'";
try
{
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(user, pwd);
ftp.KeepAlive = true;
ftp.UseBinary = false; //Use ascii.
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(inputfilepath);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
catch (WebException ex)
{
String status = ((FtpWebResponse)ex.Response).StatusDescription;
throw new Exception(status);
}
【问题讨论】:
-
您是否考虑过查看
Process.Start来运行批处理文件,或者您想使用严格的C# 代码发送它..?你用谷歌搜索过如何使用 C# 通过 FTP 连接和发送文件吗?网上有很多例子 -
是的,它必须在 C# 上,是的,我查看了链接,但我发现它对我没有帮助。我使用与我的批处理文件相同的凭据,上传文件没有问题。
-
我只是更新错误消息并将 x 替换为虚拟名称。 examplefiles 是我在 cmd 脚本中使用的真实名称,并且可以正常工作。
-
已更新!,下次我会更加小心,不要错过任何问题。
-
欣赏它。我现在要清理cmets。你今天早上投了我的赞成票。
标签: c# .net ftp mainframe ftpwebrequest