問題描述
我使用 cmd (Windows) 將文件發(fā)送到 IBM 大型機并且工作正常,如下所示:
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
我需要將其轉(zhuǎn)換為 C#.我一直在嘗試使用 FtpWebRequest
但沒有運氣.我不知道如何包含我猜的數(shù)據(jù)集.當(dāng)我運行應(yīng)用程序時,出現(xiàn)以下錯誤:
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 "遠(yuǎn)程服務(wù)器返回錯誤:(550) 文件不可用(例如,找不到文件,無法訪問)."550 無法存儲遠(yuǎn)程服務(wù)器返回錯誤:(550) 文件不可用(例如,找不到文件,無法訪問).
((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 無法存儲/'ABCD.AA.C58FC.ABC1FD.ZP3ABC/examplefile' "
((FtpWebResponse)ex.Response).StatusDescription "550 Unable to store /'ABCD.AA.C58FC.ABC1FD.ZP3ABC/examplefile' "
這是我在 C# 中得到的內(nèi)容
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);
}
推薦答案
您沒有指定運行 ftp
腳本的平臺.我假設(shè)是 Windows.
You didn't specify what platform you run the ftp
script at. I assume Windows.
當(dāng)你使用 Windows ftp
命令 put
比如:
When you use Windows ftp
command put
like:
put localpath remotepath
它會在 FTP 服務(wù)器上進行以下調(diào)用:
it results in following call on the FTP server:
STOR remotefile
類似地,如果您將 FtpWebRequest
與類似的 URL 一起使用
Similarly if you use FtpWebRequest
with an URL like
ftp://example.com/remotepath
在 FTP 服務(wù)器上導(dǎo)致以下(相同)調(diào)用:
is results in following (same) call on the FTP server:
STORE remotepath
請注意,主機名 (example.com
) 之后的第一個斜杠被省略.
Note that the first slash after hostname (example.com
) is omitted.
這意味著您的 ftp
腳本命令:
This means that your ftp
script commands:
Open abc.wyx.state.aa.bb
...
Put examplefile 'ABCD.AA.C5879.ABC123.123ABC'
翻譯成FtpWebRequest
URL,如:
string ftpfullpath = @"ftp://abc.wyx.state.aa.bb/'ABCD.AA.C5879.ABC123.123ABC'";
這兩個結(jié)果都會在 FTP 服務(wù)器上調(diào)用:
Both result in this call on the FTP server:
STOR 'ABCD.AA.C5879.ABC123.123ABC'
<小時>
相反,您的 ftp
代碼與
string ftpfullpath = @"ftp://abc.wyx.state.aa.bb//'ABCD.AA.C5879.ABC123.123ABC'/examplefile'";
結(jié)果:
STOR /'ABCD.AA.C5879.ABC123.123ABC'/examplefile'
它看起來不適合大型機.
It does not look correct for mainframe.
我的 C# 代碼的會話記錄:
Transcript of a session by my C# code:
USER user
331 Password required for user
PASS password
230 Logged on
OPTS utf8 on
200 UTF8 mode enabled
PWD
257 "/" is current directory.
TYPE A
200 Type set to A
PASV
227 Entering Passive Mode (zzz,zzz,zzz,zzz,193,162)
STOR 'ABCD.AA.C5879.ABC123.123ABC'
150 Connection accepted
226 Transfer OK
我的 ftp
腳本的會話記錄:
Transcript of the session by my ftp
script:
USER user
331 Password required for user
PASS password
230 Logged on
PORT zzz,zzz,zzz,zzz,193,186
200 Port command successful
STOR 'ABCD.AA.C5879.ABC123.123ABC'
150 Opening data channel for file transfer.
226 Transfer OK
QUIT
221 Goodbye
我已經(jīng)針對 FileZilla FTP 服務(wù)器對此進行了測試,因此顯然 FTP 服務(wù)器的響應(yīng)在大型機 FTP 上會有所不同.但是客戶端的FTP命令應(yīng)該是一樣的.
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.
這篇關(guān)于使用 C# 到 FTP 文件到大型機,包括數(shù)據(jù)集 - 將 FTP 腳本翻譯成 FtpWebRequest 代碼的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!