I use a cmd (Windows) to send file to an IBM Mainframe and works fine it's something like this:
Open abc.wyx.state.aa.bb
User
Pass
lcd c:\Transfer>
Put examplefile 'ABCD.AA.C58FC.ABC1FD.ZP3ABC'
close
bye
I need to convert this to C#. I have been trying using FtpWebRequest
but no luck. I cannot figure out how include the dataset I guess. When I run the application I got the following error:
((System.Exception)(ex)).Message "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)." 550 Unable to store The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
((FtpWebResponse)ex.Response).StatusDescription "550 Unable to store /'ABCD.AA.C58FC.ABC1FD.ZP3ABC/examplefile'\r\n"
Here is what I got in 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);
}
You didn't specify what platform you run the
ftp
script at. I assume Windows.When you use Windows
ftp
commandput
like:it results in following call on the FTP server:
Similarly if you use
FtpWebRequest
with an URL likeis results in following (same) call on the FTP server:
Note that the first slash after hostname (
example.com
) is omitted.This means that you your
ftp
script commandstranslates to
FtpWebRequest
URL like:Both result in this call on the FTP server:
Contrary, your
ftp
code withresults in:
It does not look correct for mainframe.
Transcript of a session by my C# code:
Transcript of the session by my
ftp
script:I've tested this against FileZilla FTP server, so obviously the FTP server responses will differ on the mainframe FTP. But the FTP commands from the client should be the same.