问题
I tried Retrieving a file from a mainframe location .. using FtpWebRequest.
Every thing is working fine with Other general Servers and Getting issue only for mainframe here is the message
550 Command RETR fails: /'XXX.XXX.XXX.XX.TXT' does not exist.\r\n
I believe the URI which I am creating its because of that , you can see a "/" in that message .
here is my URI = ftp ://data.data.com//'XXX.XXX.XXX.XX.TXT'
回答1:
There has been a change made to the FtpWebRequest class from .Net 2.0/3.5 to .Net Framework 4 which was related to CWD protocol commands.which prevents to use CWD command before our actual requested command. so i forced FTPWebRequest class to behave like .net 2.0. Here is the solution to force FtpWebRequest to behave like .net 2.0/3.5 https://support.microsoft.com/en-us/kb/2134299
private static void SetMethodRequiresCWD()
{
Type requestType = typeof(FtpWebRequest);
FieldInfo methodInfoField = requestType.GetField("m_MethodInfo", BindingFlags.NonPublic | BindingFlags.Instance);
Type methodInfoType = methodInfoField.FieldType;
FieldInfo knownMethodsField = methodInfoType.GetField("KnownMethodInfo", BindingFlags.Static | BindingFlags.NonPublic);
Array knownMethodsArray = (Array)knownMethodsField.GetValue(null);
FieldInfo flagsField = methodInfoType.GetField("Flags", BindingFlags.NonPublic | BindingFlags.Instance);
int MustChangeWorkingDirectoryToPath = 0x100;
foreach (object knownMethod in knownMethodsArray)
{
int flags = (int)flagsField.GetValue(knownMethod);
flags |= MustChangeWorkingDirectoryToPath;
flagsField.SetValue(knownMethod, flags);
}
}
回答2:
FTP to the mainframe is complicated. There are two parallel file systems that FTP has access to, one consisting of z/OS datasets, and the other consisting of the USS file system. My guess is that your FTP server is set up to show you the z/OS file system, and you need to first switch to the USS file system in order to retrieve what you want. I suspect that prefacing your get command with a 'cd ' command would fix things, or specifying the full path, including leading /, would as well.
Talk to your system programmer/read the CommServer documentation.
来源:https://stackoverflow.com/questions/32443477/unable-to-ftp-to-mainframe-location