Use C# to FTP file to mainframe including dataset - Translate FTP script to FtpWebRequest code

倾然丶 夕夏残阳落幕 提交于 2019-12-01 10:42:59

You didn't specify what platform you run the ftp script at. I assume Windows.

When you use Windows ftp command put like:

put localpath remotepath

it results in following call on the FTP server:

STOR remotefile

Similarly if you use FtpWebRequest with an URL like

ftp://example.com/remotepath

is results in following (same) call on the FTP server:

STORE remotepath

Note that the first slash after hostname (example.com) is omitted.


This means that you your ftp script commands

Open abc.wyx.state.aa.bb
...
Put examplefile 'ABCD.AA.C5879.ABC123.123ABC'

translates to FtpWebRequest URL like:

string ftpfullpath = @"ftp://abc.wyx.state.aa.bb/'ABCD.AA.C5879.ABC123.123ABC'";

Both result in this call on the FTP server:

STOR 'ABCD.AA.C5879.ABC123.123ABC'

Contrary, your ftp code with

string ftpfullpath = @"ftp://abc.wyx.state.aa.bb//'ABCD.AA.C5879.ABC123.123ABC'/examplefile'";

results in:

STOR /'ABCD.AA.C5879.ABC123.123ABC'/examplefile'

It does not look correct for mainframe.


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

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!